mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
add endpoint to get sharedCalendar
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user