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