query store
This commit is contained in:
parent
7ca51c3670
commit
6b7b5a99d6
9 changed files with 36 additions and 8 deletions
|
@ -1,10 +1,13 @@
|
|||
import { DynamicQueryStructure } from "../type/dynamicQueries";
|
||||
|
||||
export interface CreateQueryStoreCommand {
|
||||
query: string;
|
||||
title: string;
|
||||
query: string | DynamicQueryStructure;
|
||||
}
|
||||
|
||||
export interface UpdateQueryStoreCommand {
|
||||
id: number;
|
||||
query: string;
|
||||
query: string | DynamicQueryStructure;
|
||||
}
|
||||
|
||||
export interface DeleteQueryStoreCommand {
|
||||
|
|
|
@ -15,7 +15,9 @@ export default abstract class QueryStoreCommandHandler {
|
|||
.insert()
|
||||
.into(query)
|
||||
.values({
|
||||
query: createQueryStore.query,
|
||||
title: createQueryStore.title,
|
||||
query:
|
||||
typeof createQueryStore.query == "string" ? createQueryStore.query : JSON.stringify(createQueryStore.query),
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -36,7 +38,8 @@ export default abstract class QueryStoreCommandHandler {
|
|||
.createQueryBuilder()
|
||||
.update(query)
|
||||
.set({
|
||||
queryStore: updateQueryStore.query,
|
||||
query:
|
||||
typeof updateQueryStore.query == "string" ? updateQueryStore.query : JSON.stringify(updateQueryStore.query),
|
||||
})
|
||||
.where("id = :id", { id: updateQueryStore.id })
|
||||
.execute()
|
||||
|
|
|
@ -42,14 +42,16 @@ export async function getQueryStoreById(req: Request, res: Response): Promise<an
|
|||
*/
|
||||
export async function createQueryStore(req: Request, res: Response): Promise<any> {
|
||||
const query = req.body.query;
|
||||
const title = req.body.title;
|
||||
|
||||
let createQueryStore: CreateQueryStoreCommand = {
|
||||
title: title,
|
||||
query: query,
|
||||
};
|
||||
|
||||
await QueryStoreCommandHandler.create(createQueryStore);
|
||||
let id = await QueryStoreCommandHandler.create(createQueryStore);
|
||||
|
||||
res.sendStatus(204);
|
||||
res.status(200).send(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,9 @@ export class query {
|
|||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255, unique: true })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "text", default: "" })
|
||||
query: string;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ export default abstract class QueryStoreFactory {
|
|||
public static mapToSingle(record: query): QueryStoreViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
query: record.query,
|
||||
title: record.title,
|
||||
query: record.query.startsWith("{") ? JSON.parse(record.query) : record.query,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ export class QueryStore1734187754677 implements MigrationInterface {
|
|||
name: "query",
|
||||
columns: [
|
||||
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
|
||||
{ name: "title", type: "varchar", length: "255", isNullable: false, isUnique: true },
|
||||
{ name: "query", type: "text", isNullable: false, default: "''" },
|
||||
],
|
||||
}),
|
||||
|
|
|
@ -15,6 +15,12 @@ export class MemberDataViews1734520998539 implements MigrationInterface {
|
|||
datasource
|
||||
.getRepository(member)
|
||||
.createQueryBuilder("member")
|
||||
.select("member.id", "id")
|
||||
.addSelect("member.salutation", "salutation")
|
||||
.addSelect("member.firstname", "firstname")
|
||||
.addSelect("member.lastname", "lastname")
|
||||
.addSelect("member.nameaffix", "nameaffix")
|
||||
.addSelect("member.birthdate", "birthdate")
|
||||
.addSelect("TIMESTAMPDIFF(YEAR, member.birthdate, CURDATE())", "todayAge")
|
||||
.addSelect("YEAR(CURDATE()) - YEAR(member.birthdate)", "ageThisYear"),
|
||||
}),
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { DynamicQueryStructure } from "../../type/dynamicQueries";
|
||||
|
||||
export interface QueryStoreViewModel {
|
||||
id: number;
|
||||
query: string;
|
||||
title: string;
|
||||
query: string | DynamicQueryStructure;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,12 @@ import { Salutation } from "../enums/salutation";
|
|||
datasource
|
||||
.getRepository(member)
|
||||
.createQueryBuilder("member")
|
||||
.select("member.id", "id")
|
||||
.addSelect("member.salutation", "salutation")
|
||||
.addSelect("member.firstname", "firstname")
|
||||
.addSelect("member.lastname", "lastname")
|
||||
.addSelect("member.nameaffix", "nameaffix")
|
||||
.addSelect("member.birthdate", "birthdate")
|
||||
.addSelect("TIMESTAMPDIFF(YEAR, member.birthdate, CURDATE())", "todayAge")
|
||||
.addSelect("YEAR(CURDATE()) - YEAR(member.birthdate)", "ageThisYear"),
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue