add log for endpoints

This commit is contained in:
Peter Maquiran
2024-06-17 17:04:42 +01:00
parent 58eee3ff93
commit 157ecdd10b
10 changed files with 123 additions and 42 deletions
@@ -17,6 +17,8 @@ import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { TaskService } from 'src/app/services/task.service'; import { TaskService } from 'src/app/services/task.service';
import { AttachmentsService } from 'src/app/services/attachments.service'; import { AttachmentsService } from 'src/app/services/attachments.service';
import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service';
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { isHttpError } from 'src/app/services/http.service';
@Component({ @Component({
selector: 'app-approve-event', selector: 'app-approve-event',
@@ -95,19 +97,30 @@ export class ApproveEventPage implements OnInit {
} }
async getTask() { @XTracerAsync({name:'ApproveEventPage/getTask', log: false, bugPrint: true})
async getTask(tracing?: TracingType) {
const res = await this.AgendaDataRepositoryService.getEventToApproveById(this.serialNumber) const res = await this.AgendaDataRepositoryService.getEventToApproveById(this.serialNumber, tracing)
console.log(res)
if (res.isOk()) { if (res.isOk()) {
this.loadedEvent = res.value; this.loadedEvent = res.value;
this.today = new Date(res.value.workflowInstanceDataFields.StartDate); this.today = new Date(res.value.workflowInstanceDataFields.StartDate);
// //
this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]); this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
this.loadedAttachments = res.value.Attachments this.loadedAttachments = res.value.Attachments
} else { tracing.setAttribute('outcome', 'success')
console.log(res.error.status) } else if(isHttpError(res.error)) {
tracing.setAttribute('outcome', 'failed')
tracing.bugFlag()
this.httpErrorHandle.httpStatusHandle(res.error) this.httpErrorHandle.httpStatusHandle(res.error)
} else if(!isHttpError(res.error)) {
tracing.setAttribute('outcome', 'failed')
tracing.bugFlag()
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #12')
} }
} }
@@ -17,6 +17,7 @@ import { TracingType } from '../../monitoring/opentelemetry/tracer';
import { APINODReturn, APIReturn } from '../../decorator/api-validate-schema.decorator'; import { APINODReturn, APIReturn } from '../../decorator/api-validate-schema.decorator';
import { EventListDataOutputDTOSchema, EventListOutputDTOSchema } from './model/eventListDTOOutput'; import { EventListDataOutputDTOSchema, EventListOutputDTOSchema } from './model/eventListDTOOutput';
import { EventToApproveDataOutputDTOSchema } from './model/eventToApproveListOutputDTO'; import { EventToApproveDataOutputDTOSchema } from './model/eventToApproveListOutputDTO';
import { EventOutputDTOSchema } from './model/eventDTOOutput';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -58,16 +59,23 @@ export class AgendaDataRepositoryService {
} }
} }
async getEventToApproveById(id: string) { async getEventToApproveById(id: string, tracing?: TracingType) {
try { try {
const result = await this.agendaDataService.getEvent(id).pipe( const result = await this.agendaDataService.getEvent(id).pipe(
map((response) => { map((response) => {
return EventToApproveDetailsMapper.toDomain(response.data) APINODReturn(EventOutputDTOSchema, response, 'get/Events/${id}', tracing)
return EventToApproveDetailsMapper.toDomain(response)
}) })
).toPromise() ).toPromise()
return ok(result) return ok(result)
} catch (e) { } catch (e) {
if(isHttpError(e)) {
tracing?.setAttribute('status.code', e.status.toString())
} else {
tracing?.setAttribute('map.error', 'true')
tracing?.setAttribute('map.error.context', JSON.stringify(e))
}
return err(e as HttpErrorResponse) return err(e as HttpErrorResponse)
} }
@@ -14,7 +14,9 @@ function getTextInsideParentheses(inputString) {
export class EventMapper { export class EventMapper {
constructor() {} constructor() {}
static toDomain(dto: EventOutputDTO) { static toDomain(_dto: EventOutputDTO) {
const dto = _dto.data;
let category; let category;
if(dto.category == EEventCategory.Oficial) { if(dto.category == EEventCategory.Oficial) {
@@ -16,7 +16,9 @@ function getTextInsideParentheses(inputString) {
export class EventToApproveDetailsMapper { export class EventToApproveDetailsMapper {
constructor() {} constructor() {}
static toDomain(dto: EventOutputDTO): EventToApproveDetails { static toDomain(_dto: EventOutputDTO): EventToApproveDetails {
let dto = _dto.data
let category; let category;
if(dto.category == EEventCategory.Oficial) { if(dto.category == EEventCategory.Oficial) {
@@ -1,4 +1,5 @@
import { z } from 'zod'; import { z } from 'zod';
import { EAttendeeType, EEventCategory, EEventOwnerType, EEventStatus, EEventType } from './enums';
export const AttachmentInputDTOSchema = z.object({ export const AttachmentInputDTOSchema = z.object({
id: z.string().nullable(), id: z.string().nullable(),
@@ -7,7 +8,7 @@ export const AttachmentInputDTOSchema = z.object({
description: z.string().nullable(), description: z.string().nullable(),
applicationId: z.number().int(), applicationId: z.number().int(),
}).strict(); }).strict();
const EAttendeeTypeDTO = z.enum(["Required", "Acknowledgment", "Optional"]); const EAttendeeTypeDTO = z.nativeEnum(EAttendeeType);
const CommentSchema = z.object({ const CommentSchema = z.object({
@@ -18,7 +19,7 @@ const CommentSchema = z.object({
const AttendeeSchema = z.object({ const AttendeeSchema = z.object({
id: z.string(), id: z.string(),
name: z.string(), name: z.string(),
attendeeType: z.enum(["Required", "Acknowledgment", "Optional"]), // ["Required", "Acknowledgment", "Optional"] = [1,2,3] attendeeType: z.nativeEnum(EAttendeeType), // ["Required", "Acknowledgment", "Optional"] = [1,2,3]
emailAddress: z.string(), emailAddress: z.string(),
wxUserId: z.number(), wxUserId: z.number(),
}); });
@@ -47,27 +48,32 @@ const EventRecurrenceSchema = z.object({
until: z.string() until: z.string()
}); });
export const EventOutputDTOSchema = z.object({ export const EventOutputDTOSchema = z.object({
id: z.string(), success: z.boolean(),
owner: OwnerSchema, message: z.string(),
ownerType: z.number(), // ["PR", "MD", "Other"] = [1,2,3], data: z.object({
subject: z.string(), id: z.string(),
body: z.string(), owner: OwnerSchema,
location: z.string(), ownerType: z.nativeEnum(EEventOwnerType), // ["PR", "MD", "Other"] = [1,2,3],
startDate: z.string(), subject: z.string(),
endDate: z.string(), body: z.string(),
type: z.string(), location: z.string(),
category: z.number(), // ['Oficial', 'Pessoal'] = [1, 2] startDate: z.string(),
attendees: z.array(AttendeeSchema), endDate: z.string(),
isRecurring: z.boolean(), type: z.nativeEnum(EEventType),
eventRecurrence: EventRecurrenceSchema, category: z.nativeEnum(EEventCategory), // ['Oficial', 'Pessoal'] = [1, 2]
hasAttachments: z.boolean(), attendees: z.array(AttendeeSchema),
attachments: z.array(AttachmentInputDTOSchema), isRecurring: z.boolean(),
comments: z.array(CommentSchema), eventRecurrence: EventRecurrenceSchema,
isPrivate: z.boolean(), hasAttachments: z.boolean(),
isAllDayEvent: z.boolean(), attachments: z.array(AttachmentInputDTOSchema),
organizer: OrganizerSchema, comments: z.array(CommentSchema),
status: z.number(), // ['Pending', 'Revision', 'Approved', 'Declined', 'Communicated', 'ToCommunicate'] = [1, 2, 3, 4, 5, 6] isPrivate: z.boolean(),
}); isAllDayEvent: z.boolean(),
organizer: OrganizerSchema,
status: z.nativeEnum(EEventStatus), // ['Pending', 'Revision', 'Approved', 'Declined', 'Communicated', 'ToCommunicate'] = [1, 2, 3, 4, 5, 6]
}),
}).nullable();
export type EventOutputDTO = z.infer<typeof EventOutputDTOSchema> export type EventOutputDTO = z.infer<typeof EventOutputDTOSchema>
@@ -1,15 +1,24 @@
import { z } from "zod"; import { z } from "zod";
import { EEventOwnerType, EEventType, EEventCategory, EEventStatus } from "./enums"; import { EEventOwnerType, EEventType, EEventCategory, EEventStatus } from "./enums";
const OwnerSchema = z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string(),
userPhoto: z.string(),
});
const EventToApproveList = z.array(z.object({ const EventToApproveList = z.array(z.object({
id: z.string().uuid(), id: z.string().uuid(),
owner: z.string().nullable(), owner: OwnerSchema,
ownerType: z.nativeEnum(EEventOwnerType), ownerType: z.nativeEnum(EEventOwnerType),
subject: z.string(), subject: z.string(),
body: z.string(), body: z.string(),
location: z.string().nullable(), location: z.string().nullable(),
startDate: z.string().datetime(), startDate: z.string().datetime({ offset: true }),
endDate: z.string().datetime(), endDate: z.string().datetime({ offset: true }),
type: z.nativeEnum(EEventType), type: z.nativeEnum(EEventType),
category: z.nativeEnum(EEventCategory), category: z.nativeEnum(EEventCategory),
isRecurring: z.boolean(), isRecurring: z.boolean(),
@@ -27,6 +27,10 @@ export class CaptureLogService {
} }
setToken() {
}
interceptLogs() { interceptLogs() {
(() => { (() => {
const originalConsoleLog = console.log; const originalConsoleLog = console.log;
@@ -169,8 +169,6 @@ export class EventsToApprovePage implements OnInit {
this.list = this.TaskService.reorderList(this.ordinance, list) this.list = this.TaskService.reorderList(this.ordinance, list)
} }
console.log(this.list)
} }
@@ -217,6 +215,7 @@ export class EventsToApprovePage implements OnInit {
} }
if(userId) { if(userId) {
let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({ let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({
userId, userId,
status: EEventFilterStatus.Pending status: EEventFilterStatus.Pending
@@ -231,7 +230,6 @@ export class EventsToApprovePage implements OnInit {
this.eventoaprovacaostore.save(segment, []) this.eventoaprovacaostore.save(segment, [])
} }
this.showLoader = false;
} else { } else {
tracing.setAttribute('outcome', 'failed') tracing.setAttribute('outcome', 'failed')
@@ -240,12 +238,14 @@ export class EventsToApprovePage implements OnInit {
if(!isHttpError(allEvents.error)) { if(!isHttpError(allEvents.error)) {
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #4') this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #4')
} }
this.showLoader = false;
} }
} else { } else {
tracing.setAttribute('calling', 'early')
console.warn('calling to early Events-to-approve/LoadToApproveEvents') console.warn('calling to early Events-to-approve/LoadToApproveEvents')
} }
this.showLoader = false;
} }
getFromDB() {} getFromDB() {}
+37
View File
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularRewrite" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<httpProtocol>
<customHeaders>
<!-- Iframe on the same host only -->
<add name="Content-Security-Policy" value="frame-ancestors https://gdviewer-dev.dyndns.info/" />
<!-- HTTPS on -->
<add name="Strict-Transport-Security" value="max-age=31536000" />
<add name="Referrer-Policy" value="no-referrer" />
<add name="X-Content-Type-Options" value="nosniff" />
<!-- <add e="Expect-CT" value="enforce, max-age=86400" /> -->
<!-- Permision -->
<add name="Permissions-Policy" value="camera=(), microphone=*" />
<!-- same origin only -->
<add name="Cross-Origin-Resource-Policy" value="cross-origin" />
<!-- same origin only -->
<add name="Cross-Origin-Opener-Policy" value="require-corp" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
+1 -1
View File
@@ -1,5 +1,5 @@
export let versionData = { export let versionData = {
"shortSHA": "680f573P46", "shortSHA": "680f573P466",
"SHA": "680f57313f4d97d944e96c6e3457b7f1a9f379f0", "SHA": "680f57313f4d97d944e96c6e3457b7f1a9f379f0",
"branch": "notification-header/feature", "branch": "notification-header/feature",
"lastCommitAuthor": "'Peter Maquiran'", "lastCommitAuthor": "'Peter Maquiran'",