mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
monit notification
This commit is contained in:
@@ -18,6 +18,8 @@ import { APINODReturn, APIReturn } from '../../decorator/api-validate-schema.dec
|
||||
import { EventListDataOutputDTOSchema, EventListOutputDTOSchema } from './model/eventListDTOOutput';
|
||||
import { EventToApproveDataOutputDTOSchema } from './model/eventToApproveListOutputDTO';
|
||||
import { EventOutputDTOSchema } from './model/eventDTOOutput';
|
||||
import { SharedCalendarListDetectChanges } from './async/change/shareCalendarChangeDetector';
|
||||
import { SharedCalendarListItemOutputDTO } from './model/sharedCalendarOutputDTO';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -30,7 +32,7 @@ export class AgendaDataRepositoryService {
|
||||
private agendaLocalDataSourceService: AgendaLocalDataSourceService
|
||||
) { }
|
||||
|
||||
createOwnCalendar() {
|
||||
createOwnCalendar(): SharedCalendarListItemOutputDTO {
|
||||
const currentUserCalendar = {
|
||||
wxUserId: SessionStore.user.UserId,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
@@ -41,7 +43,7 @@ export class AgendaDataRepositoryService {
|
||||
date: '',
|
||||
}
|
||||
|
||||
return this.agendaLocalDataSourceService.createCalendar(currentUserCalendar)
|
||||
return currentUserCalendar
|
||||
}
|
||||
|
||||
async getEventById(id: string, tracing?: TracingType) {
|
||||
@@ -54,6 +56,7 @@ export class AgendaDataRepositoryService {
|
||||
).toPromise()
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
tracing.setAttribute('eventId', id)
|
||||
if(isHttpError(e)) {
|
||||
tracing?.setAttribute('status.code', e.status.toString())
|
||||
if (e.status == 400) {
|
||||
@@ -81,6 +84,7 @@ export class AgendaDataRepositoryService {
|
||||
).toPromise()
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
tracing.setAttribute('eventId', id)
|
||||
if(isHttpError(e)) {
|
||||
tracing?.setAttribute('status.code', e.status.toString())
|
||||
if (e.status == 400) {
|
||||
@@ -234,22 +238,41 @@ export class AgendaDataRepositoryService {
|
||||
async getSharedCalendar() {
|
||||
|
||||
const result = await this.agendaDataService.getSharedCalendar()
|
||||
const localList = await this.agendaLocalDataSourceService.geCalendars()
|
||||
|
||||
if (result.isOk()) {
|
||||
|
||||
if (result.value?.data) {
|
||||
|
||||
await this.agendaLocalDataSourceService.clearSharedCalendar()
|
||||
await this.createOwnCalendar()
|
||||
return await this.agendaLocalDataSourceService.bulkCreate(result.value.data)
|
||||
if(!result.value?.data) {
|
||||
result.value.data = [this.createOwnCalendar()]
|
||||
} else {
|
||||
await this.agendaLocalDataSourceService.clearSharedCalendar()
|
||||
await this.createOwnCalendar()
|
||||
return result
|
||||
result.value.data.push(this.createOwnCalendar())
|
||||
}
|
||||
|
||||
const { remove, insert, update } = SharedCalendarListDetectChanges(localList, result.value.data)
|
||||
|
||||
for(const item of insert) {
|
||||
this.agendaLocalDataSourceService.createCalendar(item)
|
||||
}
|
||||
|
||||
for(const item of remove) {
|
||||
this.agendaLocalDataSourceService.removeCalendar(item)
|
||||
}
|
||||
|
||||
} else {
|
||||
await this.agendaLocalDataSourceService.clearSharedCalendar()
|
||||
return await this.createOwnCalendar()
|
||||
|
||||
if(isHttpError(result.error)) {
|
||||
if (result.error.status == 404) {
|
||||
const remove = localList.filter(e => e.wxUserId != SessionStore.user.UserId)
|
||||
|
||||
for(const item of remove) {
|
||||
this.agendaLocalDataSourceService.removeCalendar(item)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const item = this.createOwnCalendar()
|
||||
this.agendaLocalDataSourceService.createCalendar(item)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,16 @@ export class AgendaLocalDataSourceService {
|
||||
}
|
||||
}
|
||||
|
||||
async removeCalendar(data: SharedCalendarListItemOutputDTO) {
|
||||
// db.eve
|
||||
try {
|
||||
const result = await AgendaDataSource.shareCalendar.delete(data.wxUserId)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
clearSharedCalendar() {
|
||||
// db.eve
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { z } from "zod";
|
||||
import { SharedCalendarListItemOutputDTO } from "../../model/sharedCalendarOutputDTO";
|
||||
|
||||
type Changes = {
|
||||
insert: SharedCalendarListItemOutputDTO[];
|
||||
update: SharedCalendarListItemOutputDTO[];
|
||||
remove: SharedCalendarListItemOutputDTO[];
|
||||
};
|
||||
|
||||
export function SharedCalendarListDetectChanges(
|
||||
localList: SharedCalendarListItemOutputDTO[],
|
||||
serverList: SharedCalendarListItemOutputDTO[]
|
||||
): Changes {
|
||||
const changes: Changes = { insert: [], update: [], remove: [] };
|
||||
|
||||
const localMap = new Map(localList.map(item => [item.wxUserId, item]));
|
||||
const serverMap = new Map(serverList.map(item => [item.wxUserId, item]));
|
||||
|
||||
// Detect new or updated items
|
||||
for (const [id, serverItem] of serverMap) {
|
||||
const localItem = localMap.get(id);
|
||||
if (!localItem) {
|
||||
changes.insert.push(serverItem);
|
||||
} else if (localItem.wxFullName !== serverItem.wxFullName) {
|
||||
changes.update.push(serverItem);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect deleted items
|
||||
for (const [id, localItem] of localMap) {
|
||||
if (!serverMap.has(id)) {
|
||||
changes.remove.push(localItem);
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export enum EEventFilterStatus {
|
||||
Declined,
|
||||
Communicated,
|
||||
ToCommunicate,
|
||||
AllToCommunicate,
|
||||
AllToCommunicate, // approvado e to communicate
|
||||
PendingEvents,
|
||||
}
|
||||
|
||||
@@ -41,11 +41,10 @@ export enum EEventType
|
||||
Travel,
|
||||
Conference,
|
||||
}
|
||||
|
||||
|
||||
|
||||
export enum EAttendeeType {
|
||||
Required,
|
||||
Acknowledgment,
|
||||
Optional
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user