ff-admin-server/src/command/club/protocol/protocolCommandHandler.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../../data-source";
import { protocol } from "../../../entity/club/protocol/protocol";
import InternalException from "../../../exceptions/internalException";
2024-10-13 15:48:01 +02:00
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand";
export default abstract class ProtocolCommandHandler {
/**
* @description create protocol
2025-01-05 14:29:31 +01:00
* @param {CreateProtocolCommand} createProtocol
2024-10-13 15:48:01 +02:00
* @returns {Promise<number>}
*/
static async create(createProtocol: CreateProtocolCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocol)
.values({
title: createProtocol.title,
date: createProtocol.date,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocol
2025-01-05 14:29:31 +01:00
* @param {SynchronizeProtocolCommand} syncProtocol
2024-10-13 15:48:01 +02:00
* @returns {Promise<void>}
*/
static async sync(syncProtocol: SynchronizeProtocolCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(protocol)
.set({
title: syncProtocol.title,
date: syncProtocol.date,
starttime: syncProtocol.starttime,
endtime: syncProtocol.endtime,
summary: syncProtocol.summary,
})
.where("id = :id", { id: syncProtocol.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}