#5-intelligent-groups #23

Merged
jkeffects merged 16 commits from #5-intelligent-groups into main 2024-12-19 09:50:45 +00:00
9 changed files with 36 additions and 8 deletions
Showing only changes of commit 6b7b5a99d6 - Show all commits

View file

@ -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 {

View file

@ -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()

View file

@ -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);
}
/**

View file

@ -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;
}

View file

@ -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,
};
}

View file

@ -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: "''" },
],
}),

View file

@ -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"),
}),

View file

@ -1,4 +1,7 @@
import { DynamicQueryStructure } from "../../type/dynamicQueries";
export interface QueryStoreViewModel {
id: number;
query: string;
title: string;
query: string | DynamicQueryStructure;
}

View file

@ -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"),
})