2024-12-14 16:11:53 +01:00
|
|
|
import { Request, Response } from "express";
|
2025-02-15 10:59:54 +01:00
|
|
|
import QueryStoreFactory from "../../../factory/admin/configuration/queryStore";
|
|
|
|
import QueryStoreService from "../../../service/configuration/queryStoreService";
|
2024-12-14 16:11:53 +01:00
|
|
|
import {
|
|
|
|
CreateQueryStoreCommand,
|
|
|
|
DeleteQueryStoreCommand,
|
|
|
|
UpdateQueryStoreCommand,
|
2025-02-15 10:59:54 +01:00
|
|
|
} from "../../../command/configuration/queryStore/queryStoreCommand";
|
|
|
|
import QueryStoreCommandHandler from "../../../command/configuration/queryStore/queryStoreCommandHandler";
|
2024-12-14 16:11:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get all queryStores
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function getAllQueryStores(req: Request, res: Response): Promise<any> {
|
|
|
|
let queryStores = await QueryStoreService.getAll();
|
|
|
|
|
|
|
|
res.json(QueryStoreFactory.mapToBase(queryStores));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get queryStore by id
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function getQueryStoreById(req: Request, res: Response): Promise<any> {
|
|
|
|
const id = parseInt(req.params.id);
|
|
|
|
|
|
|
|
let queryStore = await QueryStoreService.getById(id);
|
|
|
|
|
|
|
|
res.json(QueryStoreFactory.mapToSingle(queryStore));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description create new queryStore
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function createQueryStore(req: Request, res: Response): Promise<any> {
|
|
|
|
const query = req.body.query;
|
2024-12-18 22:27:33 +01:00
|
|
|
const title = req.body.title;
|
2024-12-14 16:11:53 +01:00
|
|
|
|
|
|
|
let createQueryStore: CreateQueryStoreCommand = {
|
2024-12-18 22:27:33 +01:00
|
|
|
title: title,
|
2024-12-14 16:11:53 +01:00
|
|
|
query: query,
|
|
|
|
};
|
|
|
|
|
2024-12-18 22:27:33 +01:00
|
|
|
let id = await QueryStoreCommandHandler.create(createQueryStore);
|
2024-12-14 16:11:53 +01:00
|
|
|
|
2024-12-18 22:27:33 +01:00
|
|
|
res.status(200).send(id);
|
2024-12-14 16:11:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description update queryStore
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function updateQueryStore(req: Request, res: Response): Promise<any> {
|
|
|
|
const id = parseInt(req.params.id);
|
|
|
|
const query = req.body.query;
|
|
|
|
|
|
|
|
let updateQueryStore: UpdateQueryStoreCommand = {
|
|
|
|
id: id,
|
|
|
|
query: query,
|
|
|
|
};
|
|
|
|
|
|
|
|
await QueryStoreCommandHandler.update(updateQueryStore);
|
|
|
|
|
|
|
|
res.sendStatus(204);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description delete queryStore
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function deleteQueryStore(req: Request, res: Response): Promise<any> {
|
|
|
|
const id = parseInt(req.params.id);
|
|
|
|
|
|
|
|
let deleteQueryStore: DeleteQueryStoreCommand = {
|
|
|
|
id: id,
|
|
|
|
};
|
|
|
|
|
|
|
|
await QueryStoreCommandHandler.delete(deleteQueryStore);
|
|
|
|
|
|
|
|
res.sendStatus(204);
|
|
|
|
}
|