67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
|
import { dataSource } from "../data-source";
|
||
|
import { query } from "../entity/query";
|
||
|
import InternalException from "../exceptions/internalException";
|
||
|
import { CreateQueryStoreCommand, DeleteQueryStoreCommand, UpdateQueryStoreCommand } from "./queryStoreCommand";
|
||
|
|
||
|
export default abstract class QueryStoreCommandHandler {
|
||
|
/**
|
||
|
* @description create queryStore
|
||
|
* @param CreateQueryStoreCommand
|
||
|
* @returns {Promise<number>}
|
||
|
*/
|
||
|
static async create(createQueryStore: CreateQueryStoreCommand): Promise<number> {
|
||
|
return await dataSource
|
||
|
.createQueryBuilder()
|
||
|
.insert()
|
||
|
.into(query)
|
||
|
.values({
|
||
|
query: createQueryStore.query,
|
||
|
})
|
||
|
.execute()
|
||
|
.then((result) => {
|
||
|
return result.identifiers[0].id;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("Failed creating queryStore", err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @description update queryStore
|
||
|
* @param UpdateQueryStoreCommand
|
||
|
* @returns {Promise<void>}
|
||
|
*/
|
||
|
static async update(updateQueryStore: UpdateQueryStoreCommand): Promise<void> {
|
||
|
return await dataSource
|
||
|
.createQueryBuilder()
|
||
|
.update(query)
|
||
|
.set({
|
||
|
queryStore: updateQueryStore.query,
|
||
|
})
|
||
|
.where("id = :id", { id: updateQueryStore.id })
|
||
|
.execute()
|
||
|
.then(() => {})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("Failed updating queryStore", err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @description delete queryStore
|
||
|
* @param DeleteQueryStoreCommand
|
||
|
* @returns {Promise<void>}
|
||
|
*/
|
||
|
static async delete(deletQueryStore: DeleteQueryStoreCommand): Promise<void> {
|
||
|
return await dataSource
|
||
|
.createQueryBuilder()
|
||
|
.delete()
|
||
|
.from(query)
|
||
|
.where("id = :id", { id: deletQueryStore.id })
|
||
|
.execute()
|
||
|
.then(() => {})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("Failed deleting queryStore", err);
|
||
|
});
|
||
|
}
|
||
|
}
|