mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
|
|
import { Injectable } from '@angular/core';
|
||
|
|
|
||
|
|
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||
|
|
import { SharedCalendarListItemOutputDTO, SharedCalendarListOutputDTO } from './model/sharedCalendarOutputDTO';
|
||
|
|
import { any, z } from 'zod';
|
||
|
|
import { err, ok } from 'neverthrow';
|
||
|
|
|
||
|
|
|
||
|
|
const tableScharedCalendar = z.object({
|
||
|
|
wxUserId: z.number(),
|
||
|
|
wxFullName: z.string(),
|
||
|
|
wxeMail: z.string().email(),
|
||
|
|
role: z.string(),
|
||
|
|
roleId: z.number(),
|
||
|
|
shareType: z.number(),
|
||
|
|
date: z.string(),
|
||
|
|
})
|
||
|
|
export type TableSharedCalendar = z.infer<typeof tableScharedCalendar>
|
||
|
|
|
||
|
|
// Database declaration (move this to its own module also)
|
||
|
|
export const AgendaDataSource = new Dexie('AgendaDataSource') as Dexie & {
|
||
|
|
shareCalendar: EntityTable<TableSharedCalendar, 'wxUserId'>;
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
AgendaDataSource.version(1).stores({
|
||
|
|
shareCalendar: 'wxUserId, wxFullName, wxeMail, role, roleId, shareType, startDate, endDate'
|
||
|
|
});
|
||
|
|
|
||
|
|
@Injectable({
|
||
|
|
providedIn: 'root'
|
||
|
|
})
|
||
|
|
export class AgendaLocalDataSourceService {
|
||
|
|
|
||
|
|
constructor() { }
|
||
|
|
|
||
|
|
async create(data: SharedCalendarListItemOutputDTO[]) {
|
||
|
|
// db.eve
|
||
|
|
try {
|
||
|
|
const result = AgendaDataSource.shareCalendar.bulkAdd(data)
|
||
|
|
return ok(result)
|
||
|
|
} catch (e) {
|
||
|
|
return err(false)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
clearSharedCalendar() {
|
||
|
|
// db.eve
|
||
|
|
try {
|
||
|
|
const result = AgendaDataSource.shareCalendar.clear()
|
||
|
|
return ok(result)
|
||
|
|
} catch (e) {
|
||
|
|
return err(false)
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|