add new endpoint to save and get draft

This commit is contained in:
Peter Maquiran
2024-09-12 18:57:45 +01:00
parent 38f51bd7e1
commit 82d6a15d5e
10 changed files with 118 additions and 66 deletions
@@ -10,6 +10,7 @@ import { EventListOutputDTO } from '../dto/eventListDTOOutput';
import { HttpService } from 'src/app/services/http.service'; import { HttpService } from 'src/app/services/http.service';
import { TracingType } from 'src/app/services/monitoring/opentelemetry/tracer'; import { TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
import { IGetDraftListByProcessIdOutput, IGetDraftListByProcessIdSchema } from '../../domain/usecase/getDraft-list-by-process-id.service'; import { IGetDraftListByProcessIdOutput, IGetDraftListByProcessIdSchema } from '../../domain/usecase/getDraft-list-by-process-id.service';
import { IDraftSaveByIdInput } from '../../domain/usecase/draft-save-by-id-use-case.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -135,4 +136,8 @@ export class AgendaDataService {
async getDraftListByProcessId(input: IGetDraftListByProcessIdSchema) { async getDraftListByProcessId(input: IGetDraftListByProcessIdSchema) {
return await this.httpService.get<IGetDraftListByProcessIdOutput>(`${this.baseUrl}/Contents/FolderId/${input.processId}`); return await this.httpService.get<IGetDraftListByProcessIdOutput>(`${this.baseUrl}/Contents/FolderId/${input.processId}`);
} }
async draftSaveById(input: IDraftSaveByIdInput) {
return await this.httpService.put<IGetDraftListByProcessIdOutput>(`${this.baseUrl}/Contents/${input.id}`, input);
}
} }
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { GetDraftListByProcessIdService, IGetDraftListByProcessIdSchema } from './usecase/getDraft-list-by-process-id.service'; import { GetDraftListByProcessIdService, IGetDraftListByProcessIdSchema } from './usecase/getDraft-list-by-process-id.service';
import { DraftSaveByIdInputSchema, DraftSaveByIdUseCaseService, IDraftSaveByIdInput } from './usecase/draft-save-by-id-use-case.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -7,10 +8,15 @@ import { GetDraftListByProcessIdService, IGetDraftListByProcessIdSchema } from '
export class AgendaService { export class AgendaService {
constructor( constructor(
private getDraftListByProcessIdService: GetDraftListByProcessIdService private getDraftListByProcessIdService: GetDraftListByProcessIdService,
private DraftSaveByIdUseCaseService: DraftSaveByIdUseCaseService
) { } ) { }
getDraftListByProcessId(input: IGetDraftListByProcessIdSchema) { getDraftListByProcessId(input: IGetDraftListByProcessIdSchema) {
return this.getDraftListByProcessIdService.execute(input) return this.getDraftListByProcessIdService.execute(input)
} }
draftSaveById(input: IDraftSaveByIdInput) {
return this.DraftSaveByIdUseCaseService.execute(input)
}
} }
@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { AgendaDataService } from '../../data/data-source/agenda-data.service';
import { z } from 'zod';
export const DraftSaveByIdInputSchema = z.object({
description: z.string(),
status: z.boolean(),
content: z.string(),
path: z.string(),
ownerId: z.number(),
id: z.number()
})
export type IDraftSaveByIdInput= z.infer< typeof DraftSaveByIdInputSchema>
@Injectable({
providedIn: 'root'
})
export class DraftSaveByIdUseCaseService {
constructor(
private agendaDataService: AgendaDataService
) { }
async execute(input: IDraftSaveByIdInput) {
return await this.agendaDataService.draftSaveById(input)
}
}
@@ -166,7 +166,7 @@ export class DespachoPage implements OnInit {
// this.updateProcessOnDB(res); // this.updateProcessOnDB(res);
this.fulltask = res; this.fulltask = res;
this.getDocumentPdf(this.fulltask.Documents) this.getDocumentPdf({FolderID: res.workflowInstanceDataFields.FolderID})
console.log('All', this.mergedArray) console.log('All', this.mergedArray)
@@ -200,52 +200,58 @@ export class DespachoPage implements OnInit {
}); });
} }
// getDocumentPdf({FolderID}) { getDocumentPdf({FolderID}) {
// this.agendaService.getDraftListByProcessId({ this.agendaService.getDraftListByProcessId({
// processId: FolderID processId: FolderID
// }).then(( draftList => { }).then(( draftList => {
// if(draftList.isOk()) { if(draftList.isOk()) {
// const docObject = draftList.value.data.map((e) => ({ const docObject = draftList.value.data.map((e) => ({
// "ApplicationId": "", "id": e.id,
// "Assunto": e.description, "ownerId": e.ownerId,
// "DocDate": e.createdAt, "path": e.path,
// "DocId": "", "description":e.description,
// "DocNumber": "element.DocNumber", "ApplicationId": "",
// "FolderId": e.folderId, "Assunto": e.description,
// "Sender": "uuid", "DocDate": e.createdAt,
// "SourceDocId": "element.SourceDocId", "DocId": "",
"DocNumber": "element.DocNumber",
"FolderId": e.folderId,
"content": e.content,
"Sender": "uuid",
"SourceDocId": "element.SourceDocId",
"status": e.status,
}))
for(const file of docObject) {
this.mergedArray.push(file);
}
}
}));
}
// getDocumentPdf(Documents: any) {
// Documents.forEach(element => {
// let docObject = {
// "ApplicationId": element.ApplicationId,
// "Assunto": element.Assunto,
// "DocDate": element.DocDate,
// "DocId": element.DocId,
// "DocNumber": element.DocNumber,
// "FolderId": element.FolderId,
// "Sender": element.Sender,
// "SourceDocId": element.SourceDocId,
// "content": "", // "content": "",
// "path": "", // "path": "",
// "ownerId": "", // "ownerId": "",
// "status": "", // "status": "",
// })) // }
// this.mergedArray.push(docObject); // this.mergedArray.push(docObject);
// });
// } // }
// }));
// }
getDocumentPdf(Documents: any) {
Documents.forEach(element => {
let docObject = {
"ApplicationId": element.ApplicationId,
"Assunto": element.Assunto,
"DocDate": element.DocDate,
"DocId": element.DocId,
"DocNumber": element.DocNumber,
"FolderId": element.FolderId,
"Sender": element.Sender,
"SourceDocId": element.SourceDocId,
"content": "",
"path": "",
"ownerId": "",
"status": "",
}
this.mergedArray.push(docObject);
});
}
@XTracerAsync({name:'task/getDraft', bugPrint: true}) @XTracerAsync({name:'task/getDraft', bugPrint: true})
getDraft(split_stringDraft: string[], tracing?: TracingType) { getDraft(split_stringDraft: string[], tracing?: TracingType) {
@@ -11,8 +11,9 @@ export const ViewerAttachmentParams = z.object({
SourceDocId: z.string(), SourceDocId: z.string(),
content: z.string().nonempty(), content: z.string().nonempty(),
path: z.string().nonempty(), path: z.string().nonempty(),
ownerId: z.string().nonempty(), ownerId: z.number(),
status: z.string().nonempty(), status: z.string().nonempty(),
id: z.number().optional()
}) })
export type ViewerAttachment = z.infer<typeof ViewerAttachmentParams>; export type ViewerAttachment = z.infer<typeof ViewerAttachmentParams>;
@@ -23,7 +23,7 @@
<div> <div>
<div class="subject add-ellipsis">{{ attachment.Assunto || "Sem assunto" }}</div> <div class="subject add-ellipsis">{{ attachment.Assunto || "Sem assunto" }}</div>
<div class="user" > <div class="user" >
{{ attachment.Sender }} {{ attachment?.Sender }}
</div> </div>
</div> </div>
@@ -65,10 +65,10 @@
</div> </div>
<div class="flex-1" [ngClass]="{'container-img': loading}"> <div class="flex-1" [ngClass]="{'container-img': loading}">
<div [ngClass]="{'d-none': draft}" #iframeContainer class="height-100 flex-1 " [ngClass]="{'container-img': loading}" ></div> <div [ngClass]="{'d-none': draft, 'container-img': loading}" #iframeContainer class="height-100 flex-1 " ></div>
<editor <editor
*ngIf="taskViewerAttachment[selectedIndex].content" *ngIf="draft"
class="container-img height-100 flex-1" class="container-img height-100 flex-1"
apiKey="wr5dk69kive0qr9ig6y5spqvlj3a0tsiwnzdsexnz241k69p" apiKey="wr5dk69kive0qr9ig6y5spqvlj3a0tsiwnzdsexnz241k69p"
[(ngModel)]="taskViewerAttachment[selectedIndex].content" [(ngModel)]="taskViewerAttachment[selectedIndex].content"
@@ -73,3 +73,7 @@ iframe {
background-position-x: center; background-position-x: center;
background-position-y: center; background-position-y: center;
} }
.d-none {
display: none !important;
}
@@ -9,7 +9,7 @@ import { PermissionService } from 'src/app/services/permission.service';
import { from, Subject } from 'rxjs'; import { from, Subject } from 'rxjs';
import { switchMap } from 'rxjs/operators'; import { switchMap } from 'rxjs/operators';
import { Result } from 'neverthrow'; import { Result } from 'neverthrow';
import { AgendaService } from 'src/app/module/agenda/domain/agenda.service'
@Component({ @Component({
selector: 'app-viewer-attachment', selector: 'app-viewer-attachment',
templateUrl: './viewer-attachment.page.html', templateUrl: './viewer-attachment.page.html',
@@ -40,6 +40,7 @@ export class ViewerAttachmentPage implements OnInit {
private erroHandler: HttpErrorHandle, private erroHandler: HttpErrorHandle,
public p: PermissionService, public p: PermissionService,
private processService: ProcessesService, private processService: ProcessesService,
private AgendaService: AgendaService
) { } ) { }
ngOnInit() { ngOnInit() {
@@ -169,27 +170,28 @@ export class ViewerAttachmentPage implements OnInit {
// do other stuff... // do other stuff...
} }
async saveDraft(selectedIndex) {
saveDraft(selectedIndex) {
// Lógica que deseja executar em intervalos regulares // Lógica que deseja executar em intervalos regulares
console.log('Intervalo de 3 segundos...'); console.log('Intervalo de 3 segundos...');
const document = this.taskViewerAttachment[selectedIndex] const document = this.taskViewerAttachment[selectedIndex]
let objectDraft = {
const saveResult = await this.AgendaService.draftSaveById({
"status": false, "status": false,
"description": document.Assunto, "description": document.Assunto,
"content": document.content, "content": document.content,
"path": document.path, "path": document.path,
"ownerId": document.ownerId "ownerId": document.ownerId,
} "id": document.id
this.processService.SaveDraftByID(document.DocId, objectDraft).subscribe((res) => {
console.log('Saved tinymce')
}, (error) => {
this.erroHandler.httpStatusHandle(error)
}) })
if(saveResult.isOk()) {
console.log('Saved tinymce')
} else {
if(saveResult.error.status) {
this.erroHandler.httpStatusHandle(saveResult.error)
}
}
} }
onEditorContentChange() { onEditorContentChange() {
@@ -88,7 +88,7 @@
<div class="flex-1 overflow-hidden"> <div class="flex-1 overflow-hidden">
<p class="attach-title-item overflow-hidden">{{ Document.Assunto || "Sem assunto" }} <span class="document-type" *ngIf="Document.content">Rascunho</span></p> <p class="attach-title-item overflow-hidden">{{ Document.Assunto || "Sem assunto" }} <span class="document-type" *ngIf="Document.content">Rascunho</span></p>
<p class="overflow-hidden"><span class="span-left">{{ Document.Sender}}</span><span class="span-right">{{ Document.DocDate | date: 'dd-MM-yyyy HH:mm' }}</span></p> <p class="overflow-hidden"><span class="span-left">{{ Document?.Sender}}</span><span class="span-right">{{ Document.DocDate | date: 'dd-MM-yyyy HH:mm' }}</span></p>
</div> </div>
<!-- <div class="d-flex justify-center align-center font-25" (click)="clickDocumentUPdateIndex(Document.DocId, Document, Document.content);"> --> <!-- <div class="d-flex justify-center align-center font-25" (click)="clickDocumentUPdateIndex(Document.DocId, Document, Document.content);"> -->
+6 -6
View File
@@ -1,11 +1,11 @@
export let versionData = { export let versionData = {
"shortSHA": "f3e09cadf", "shortSHA": "38f51bd7e",
"SHA": "f3e09cadf241a72b4a79dbe59ac500ff54e0cea4", "SHA": "38f51bd7e14fe61747947721d048e7674d55ff9d",
"branch": "feature/agenda-api-peter", "branch": "feature/agenda-api-peter",
"lastCommitAuthor": "'Peter Maquiran'", "lastCommitAuthor": "'Peter Maquiran'",
"lastCommitTime": "'Wed Sep 11 16:04:43 2024 +0100'", "lastCommitTime": "'Wed Sep 11 16:06:47 2024 +0100'",
"lastCommitMessage": "add endpoint to get document drafts", "lastCommitMessage": "fix images",
"lastCommitNumber": "5901", "lastCommitNumber": "5902",
"changeStatus": "On branch feature/agenda-api-peter\nYour branch is ahead of 'origin/feature/agenda-api-peter' by 1 commit.\n (use \"git push\" to publish your local commits)\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: version/git-version.ts", "changeStatus": "On branch feature/agenda-api-peter\nYour branch is ahead of 'origin/feature/agenda-api-peter' by 2 commits.\n (use \"git push\" to publish your local commits)\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tnew file: src/app/module/agenda/domain/usecase/draft-save-by-id-use-case.service.ts\n\nChanges not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n (use \"git restore <file>...\" to discard changes in working directory)\n\tmodified: src/app/module/agenda/data/data-source/agenda-data.service.ts\n\tmodified: src/app/module/agenda/domain/agenda.service.ts\n\tmodified: src/app/pages/gabinete-digital/despachos/despacho/despacho.page.ts\n\tmodified: src/app/pages/gabinete-digital/viewer-attachment/prop.ts\n\tmodified: src/app/pages/gabinete-digital/viewer-attachment/viewer-attachment.page.html\n\tmodified: src/app/pages/gabinete-digital/viewer-attachment/viewer-attachment.page.scss\n\tmodified: src/app/pages/gabinete-digital/viewer-attachment/viewer-attachment.page.ts\n\tmodified: src/app/shared/gabinete-digital/generic/task-details/task-details.page.html",
"changeAuthor": "peter.maquiran" "changeAuthor": "peter.maquiran"
} }