mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add endpoint to get sharedCalendar
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AgendaDataRepositoryService } from './agenda-data-repository.service';
|
||||
|
||||
describe('AgendaDataRepositoryService', () => {
|
||||
let service: AgendaDataRepositoryService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AgendaDataRepositoryService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import { EventListToApproveMapper } from './mapper/eventToApproveListMapper';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { EventToApproveDetailsMapper } from './mapper/EventToApproveDetailsMapper';
|
||||
import { AgendaLocalDataSourceService } from './agenda-local-data-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -18,7 +19,8 @@ export class AgendaDataRepositoryService {
|
||||
|
||||
constructor(
|
||||
private agendaDataService: AgendaDataService,
|
||||
private utils: Utils
|
||||
private utils: Utils,
|
||||
private agendaLocalDataSourceService: AgendaLocalDataSourceService
|
||||
) { }
|
||||
|
||||
async getEventById(id: string) {
|
||||
@@ -167,4 +169,21 @@ export class AgendaDataRepositoryService {
|
||||
getDocumentAttachments(applicationId,userId,subject,pageNumber,pageSize) {
|
||||
return this.agendaDataService.getDocumentAttachment(applicationId,userId,subject,pageNumber,pageSize)
|
||||
}
|
||||
|
||||
async getSharedCalendar() {
|
||||
|
||||
const result = await this.agendaDataService.getSharedCalendar()
|
||||
|
||||
if(result.isOk()) {
|
||||
await this.agendaLocalDataSourceService.clearSharedCalendar()
|
||||
if(result.value?.data) {
|
||||
return await this.agendaLocalDataSourceService.create(result.value.data)
|
||||
} else {
|
||||
return result
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AgendaDataService } from './agenda-data.service';
|
||||
|
||||
describe('AgendaDataService', () => {
|
||||
let service: AgendaDataService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AgendaDataService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,11 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { EventOutputDTO } from './model/eventDTOOutput';
|
||||
import { EventInputDTO } from './model/eventInputDTO';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { SharedCalendarListOutputDTO, SharedCalendarListOutputDTOSchema } from './model/sharedCalendarOutputDTO';
|
||||
import { HttpService } from '../../http.service';
|
||||
import { APIReturn } from '../../decorator/api-validate-schema.decorator';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -11,7 +14,10 @@ import { EventInputDTO } from './model/eventInputDTO';
|
||||
export class AgendaDataService {
|
||||
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2'; // Your base URL
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private httpService: HttpService
|
||||
) { }
|
||||
|
||||
getContacts(value: string): Observable<any> {
|
||||
const params = new HttpParams().set('value', value);
|
||||
@@ -115,4 +121,10 @@ export class AgendaDataService {
|
||||
.set('PageSize', PageSize);
|
||||
return this.http.get<any>(`${this.baseUrl}/Documents/Attachments${aplicationId}`, {params});
|
||||
}
|
||||
|
||||
|
||||
@APIReturn(SharedCalendarListOutputDTOSchema)
|
||||
async getSharedCalendar() {
|
||||
return await this.httpService.get<SharedCalendarListOutputDTO>(`${this.baseUrl}/Users/id/ShareCalendar?id=${SessionStore.user.UserId}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const SharedCalendarListItemOutputDTOSchema = 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 const SharedCalendarListOutputDTOSchema = z.object({
|
||||
success: z.boolean(),
|
||||
message: z.string(),
|
||||
data: z.array(SharedCalendarListItemOutputDTOSchema),
|
||||
}).nullable();
|
||||
|
||||
export type SharedCalendarListItemOutputDTO = z.infer<typeof SharedCalendarListItemOutputDTOSchema>;
|
||||
export type SharedCalendarListOutputDTO = z.infer<typeof SharedCalendarListOutputDTOSchema>;
|
||||
Reference in New Issue
Block a user