32 lines
979 B
TypeScript
32 lines
979 B
TypeScript
|
import { dataSource } from "../data-source";
|
||
|
import { protocolPrintout } from "../entity/protocolPrintout";
|
||
|
import InternalException from "../exceptions/internalException";
|
||
|
import { CreateProtocolPrintoutCommand } from "./protocolPrintoutCommand";
|
||
|
|
||
|
export default abstract class ProtocolPrintoutCommandHandler {
|
||
|
/**
|
||
|
* @description create protocolPrintout
|
||
|
* @param {number}
|
||
|
* @returns {Promise<number>}
|
||
|
*/
|
||
|
static async create(printout: CreateProtocolPrintoutCommand): Promise<number> {
|
||
|
return await dataSource
|
||
|
.createQueryBuilder()
|
||
|
.insert()
|
||
|
.into(protocolPrintout)
|
||
|
.values({
|
||
|
title: printout.title,
|
||
|
iteration: printout.iteration,
|
||
|
filename: printout.filename,
|
||
|
protocolId: printout.protocolId,
|
||
|
})
|
||
|
.execute()
|
||
|
.then((result) => {
|
||
|
return result.identifiers[0].id;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("Failed creating protocol", err);
|
||
|
});
|
||
|
}
|
||
|
}
|