ff-admin-server/src/command/protocolDecisionCommandHandler.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-10-13 13:48:01 +00:00
import { dataSource } from "../data-source";
import { protocolDecision } from "../entity/protocolDecision";
import InternalException from "../exceptions/internalException";
import { SynchronizeProtocolDecisionCommand } from "./protocolDecisionCommand";
export default abstract class ProtocolDecisionCommandHandler {
2024-10-15 14:25:42 +00:00
/**
* @description create protocolDecision
* @param {number}
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolDecision)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
2024-10-13 13:48:01 +00:00
/**
* @description sync protocolDecision
* @param {Array<SynchronizeProtocolDecisionCommand>}
* @returns {Promise<void>}
*/
static async sync(syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolDecision)
.values(syncProtocolDecisions)
.orUpdate(["topic", "context"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}