mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { ActionLocalRepositoryService } from 'src/app/module/actions/data/repository/action-local-repository.service';
|
|
import { ActionRemoteRepositoryService } from 'src/app/module/actions/data/repository/action-remote-repository.service';
|
|
import { z } from "zod";
|
|
|
|
export const ActionGetAllOutPutSchema = z.array(z.object({
|
|
processId: z.number(),
|
|
applicationId: z.number(),
|
|
organicEntityId: z.number(),
|
|
securityId: z.number(),
|
|
serieId: z.number(),
|
|
userId: z.number(),
|
|
dateIndex: z.string().datetime(), // ISO 8601 datetime
|
|
description: z.string(),
|
|
detail: z.string(),
|
|
dateBegin: z.string().datetime(),
|
|
dateEnd: z.string().datetime(),
|
|
actionType: z.number(),
|
|
location: z.string(),
|
|
isExported: z.boolean(),
|
|
sourceLocation: z.number(),
|
|
sourceProcessId: z.number(),
|
|
}));
|
|
|
|
// Example usage:
|
|
export type ActionGetAllOutPut = z.infer<typeof ActionGetAllOutPutSchema>;
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ActionsGetAllUseCaseService {
|
|
|
|
constructor(
|
|
private remote: ActionRemoteRepositoryService,
|
|
private local: ActionLocalRepositoryService
|
|
) { }
|
|
|
|
async execute() {
|
|
|
|
var result = await this.remote.actionGetAll();
|
|
|
|
if(result.isOk()) {
|
|
const data = result.value.data.data;
|
|
|
|
this.local.createTransaction( async (table) => {
|
|
// Clear the table before inserting new data
|
|
await table.clear();
|
|
// Insert the new data
|
|
await table.bulkAdd(data);
|
|
});
|
|
}
|
|
}
|
|
}
|