mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
add endpoint to get sharedCalendar
This commit is contained in:
@@ -185,9 +185,19 @@ export class AgendaPage implements OnInit {
|
||||
public ThemeService: ThemeService,
|
||||
public p: PermissionService,
|
||||
public RoleIdService: RoleIdService,
|
||||
public AgendaDataRepositoryService: AgendaDataRepositoryService
|
||||
public AgendaDataRepositoryService: AgendaDataRepositoryService,
|
||||
) {
|
||||
|
||||
(async () => {
|
||||
const result = await this.AgendaDataRepositoryService.getSharedCalendar()
|
||||
|
||||
if(result.isOk()) {
|
||||
console.log('111', result)
|
||||
} else {
|
||||
console.log('error')
|
||||
}
|
||||
})()
|
||||
|
||||
this.dateAdapter.setLocale('es');
|
||||
this.locale = 'pt'
|
||||
|
||||
@@ -779,7 +789,6 @@ export class AgendaPage implements OnInit {
|
||||
const selectedCalendarIds = this.removeDuplicatesByOwnerUserId(this.getSelectedAgendaCalendars());
|
||||
this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds)
|
||||
|
||||
console.log('this.listToPresent', JSON.stringify(this.listToPresent) )
|
||||
const year = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate })
|
||||
this.TimelineMDList = year
|
||||
|
||||
|
||||
@@ -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>;
|
||||
@@ -75,7 +75,6 @@ export class ListBoxService {
|
||||
// daysObject[day] = object[day]
|
||||
// }
|
||||
|
||||
console.log('newStracture', newStracture)
|
||||
|
||||
return this.display(newStracture, selectedDate).year
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Result, err } from 'neverthrow';
|
||||
import { z, ZodError } from 'zod';
|
||||
import * as Sentry from '@sentry/capacitor';
|
||||
|
||||
export function APIReturn(schema: z.ZodTypeAny) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
descriptor.value = async function (...args: any[]) {
|
||||
const result: Result<any, HttpErrorResponse> = await originalMethod.apply(this, args);
|
||||
|
||||
if(result.isOk()) {
|
||||
try {
|
||||
// Validate the result using the provided schema
|
||||
schema.parse(result.value);
|
||||
|
||||
} catch (error) {
|
||||
if (error instanceof ZodError) {
|
||||
// If validation fails, throw an error with the details
|
||||
//
|
||||
console.log('unexpected data structure')
|
||||
// Capture the Zod validation error with additional context
|
||||
Sentry.withScope((scope) => {
|
||||
scope.setTag('APIReturn', 'user');
|
||||
scope.setContext('data', { data: result.value });
|
||||
Sentry.captureException(error);
|
||||
});
|
||||
console.error('Validation failed:', error.errors);
|
||||
|
||||
} else {
|
||||
console.log('failed to setup the connection successful')
|
||||
// Throw any other unexpected errors
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log()
|
||||
// result.error.
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user