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

53 lines
1.6 KiB
TypeScript

import { dataSource } from "../../../data-source";
import { protocol } from "../../../entity/club/protocol/protocol";
import InternalException from "../../../exceptions/internalException";
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand";
export default abstract class ProtocolCommandHandler {
/**
* @description create protocol
* @param {CreateProtocolCommand} createProtocol
* @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
* @param {SynchronizeProtocolCommand} syncProtocol
* @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);
});
}
}