mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 10:06:17 +08:00
0bd8160ed4
#### PR Dependency Tree * **PR #14247** 👈 * **PR #14248** This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Google Calendar integration (disabled by default): link/unlink accounts, OAuth flow, webhooks, real-time push, background sync, workspace calendars with customizable items and date-range event viewing. * **GraphQL / Client** * New queries & mutations for accounts, subscriptions, events, providers, and workspace calendar management. * **Localization** * Added localized error message for calendar provider request failures. * **Tests** * Backend tests covering sync, webhook renewal, and error/error-recovery scenarios. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import { BaseModel } from './base';
|
|
|
|
@Injectable()
|
|
export class WorkspaceCalendarModel extends BaseModel {
|
|
async get(id: string) {
|
|
return await this.db.workspaceCalendar.findUnique({
|
|
where: { id },
|
|
});
|
|
}
|
|
|
|
async getByWorkspace(workspaceId: string) {
|
|
return await this.db.workspaceCalendar.findMany({
|
|
where: { workspaceId },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
}
|
|
|
|
async getDefault(workspaceId: string) {
|
|
return await this.db.workspaceCalendar.findFirst({
|
|
where: { workspaceId },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
}
|
|
|
|
async getOrCreateDefault(workspaceId: string, createdByUserId: string) {
|
|
const existing = await this.getDefault(workspaceId);
|
|
if (existing) {
|
|
return existing;
|
|
}
|
|
|
|
return await this.db.workspaceCalendar.create({
|
|
data: {
|
|
workspaceId,
|
|
createdByUserId,
|
|
},
|
|
});
|
|
}
|
|
|
|
async updateItems(
|
|
workspaceCalendarId: string,
|
|
items: Array<{
|
|
subscriptionId: string;
|
|
sortOrder?: number | null;
|
|
colorOverride?: string | null;
|
|
}>
|
|
) {
|
|
await this.db.workspaceCalendarItem.deleteMany({
|
|
where: { workspaceCalendarId },
|
|
});
|
|
|
|
if (items.length === 0) {
|
|
return;
|
|
}
|
|
|
|
await this.db.workspaceCalendarItem.createMany({
|
|
data: items.map((item, index) => ({
|
|
workspaceCalendarId,
|
|
subscriptionId: item.subscriptionId,
|
|
sortOrder: item.sortOrder ?? index,
|
|
colorOverride: item.colorOverride ?? null,
|
|
})),
|
|
});
|
|
}
|
|
|
|
async listItems(workspaceCalendarId: string) {
|
|
return await this.db.workspaceCalendarItem.findMany({
|
|
where: { workspaceCalendarId },
|
|
orderBy: { sortOrder: 'asc' },
|
|
});
|
|
}
|
|
|
|
async listItemsByWorkspace(workspaceId: string) {
|
|
return await this.db.workspaceCalendarItem.findMany({
|
|
where: { workspaceCalendar: { workspaceId } },
|
|
orderBy: { sortOrder: 'asc' },
|
|
include: { subscription: true },
|
|
});
|
|
}
|
|
}
|