Compare commits
No commits in common. "main" and "v1.3.12" have entirely different histories.
15 changed files with 1752 additions and 1693 deletions
|
@ -1,4 +1,4 @@
|
||||||
FROM node:22-alpine AS build
|
FROM node:18-alpine AS build
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
chromium \
|
chromium \
|
||||||
|
@ -20,7 +20,7 @@ COPY . /app
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM node:22-alpine AS prod
|
FROM node:18-alpine AS prod
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
chromium \
|
chromium \
|
||||||
|
|
3251
package-lock.json
generated
3251
package-lock.json
generated
File diff suppressed because it is too large
Load diff
23
package.json
23
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ff-admin-server",
|
"name": "ff-admin-server",
|
||||||
"version": "1.4.2",
|
"version": "1.3.12",
|
||||||
"description": "Feuerwehr/Verein Mitgliederverwaltung Server",
|
"description": "Feuerwehr/Verein Mitgliederverwaltung Server",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^5.1.0",
|
"express": "^5.0.0-beta.3",
|
||||||
"express-rate-limit": "^7.5.0",
|
"express-rate-limit": "^7.5.0",
|
||||||
"express-validator": "^7.2.1",
|
"express-validator": "^7.2.1",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
|
@ -41,10 +41,10 @@
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"node-schedule": "^2.1.1",
|
"node-schedule": "^2.1.1",
|
||||||
"nodemailer": "^6.10.1",
|
"nodemailer": "^6.9.14",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pg": "^8.13.1",
|
"pg": "^8.13.1",
|
||||||
"puppeteer": "^24.6.1",
|
"puppeteer": "^23.11.1",
|
||||||
"qrcode": "^1.5.4",
|
"qrcode": "^1.5.4",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rss-parser": "^3.13.0",
|
"rss-parser": "^3.13.0",
|
||||||
|
@ -52,26 +52,25 @@
|
||||||
"speakeasy": "^2.0.0",
|
"speakeasy": "^2.0.0",
|
||||||
"sqlite3": "^5.1.7",
|
"sqlite3": "^5.1.7",
|
||||||
"typeorm": "^0.3.20",
|
"typeorm": "^0.3.20",
|
||||||
"uuid": "^11.1.0"
|
"uuid": "^10.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.14",
|
"@types/cors": "^2.8.14",
|
||||||
"@types/express": "^5.0.1",
|
"@types/express": "^4.17.17",
|
||||||
"@types/ip": "^1.1.3",
|
"@types/ip": "^1.1.3",
|
||||||
"@types/jsonwebtoken": "^9.0.6",
|
"@types/jsonwebtoken": "^9.0.6",
|
||||||
"@types/lodash.uniqby": "^4.7.9",
|
"@types/lodash.uniqby": "^4.7.9",
|
||||||
"@types/morgan": "^1.9.9",
|
"@types/morgan": "^1.9.9",
|
||||||
"@types/ms": "^2.1.0",
|
"@types/ms": "^0.7.34",
|
||||||
"@types/multer": "^1.4.12",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/mysql": "^2.15.21",
|
"@types/mysql": "^2.15.21",
|
||||||
"@types/node": "^22.14.1",
|
"@types/node": "^16.18.41",
|
||||||
"@types/node-schedule": "^2.1.6",
|
"@types/node-schedule": "^2.1.6",
|
||||||
"@types/nodemailer": "^6.4.14",
|
"@types/nodemailer": "^6.4.14",
|
||||||
"@types/pg": "~8.11.12",
|
|
||||||
"@types/qrcode": "~1.5.5",
|
"@types/qrcode": "~1.5.5",
|
||||||
"@types/speakeasy": "^2.0.10",
|
"@types/speakeasy": "^2.0.10",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^9.0.2",
|
||||||
"ts-node": "10.9.2",
|
"ts-node": "10.7.0",
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^4.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import DynamicQueryBuilder from "../../../helpers/dynamicQueryBuilder";
|
import DynamicQueryBuilder from "../../../helpers/dynamicQueryBuilder";
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import QueryStoreService from "../../../service/configuration/queryStoreService";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all table metas
|
* @description get all table metas
|
||||||
|
@ -44,23 +43,3 @@ export async function executeQuery(req: Request, res: Response): Promise<any> {
|
||||||
|
|
||||||
res.json(result);
|
res.json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description execute Query by StoreId
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function executeQueryByStoreId(req: Request, res: Response): Promise<any> {
|
|
||||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
|
||||||
let count = parseInt((req.query.count as string) ?? "25");
|
|
||||||
let noLimit = req.query.noLimit === "true";
|
|
||||||
const storeId = req.params.storeId;
|
|
||||||
|
|
||||||
let queryStore = await QueryStoreService.getById(storeId);
|
|
||||||
let query = queryStore.query.startsWith("{") ? JSON.parse(queryStore.query) : queryStore.query;
|
|
||||||
|
|
||||||
let result = await DynamicQueryBuilder.executeQuery({ query, offset, count, noLimit });
|
|
||||||
|
|
||||||
res.json(result);
|
|
||||||
}
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ import { CreateSchema1738166167472 } from "./migrations/1738166167472-CreateSche
|
||||||
import { TemplatesAndProtocolSort1742549956787 } from "./migrations/1742549956787-templatesAndProtocolSort";
|
import { TemplatesAndProtocolSort1742549956787 } from "./migrations/1742549956787-templatesAndProtocolSort";
|
||||||
import { QueryToUUID1742922178643 } from "./migrations/1742922178643-queryToUUID";
|
import { QueryToUUID1742922178643 } from "./migrations/1742922178643-queryToUUID";
|
||||||
import { NewsletterColumnType1744351418751 } from "./migrations/1744351418751-newsletterColumnType";
|
import { NewsletterColumnType1744351418751 } from "./migrations/1744351418751-newsletterColumnType";
|
||||||
import { QueryUpdatedAt1744795756230 } from "./migrations/1744795756230-QueryUpdatedAt";
|
|
||||||
|
|
||||||
const dataSource = new DataSource({
|
const dataSource = new DataSource({
|
||||||
type: DB_TYPE as any,
|
type: DB_TYPE as any,
|
||||||
|
@ -110,7 +109,6 @@ const dataSource = new DataSource({
|
||||||
TemplatesAndProtocolSort1742549956787,
|
TemplatesAndProtocolSort1742549956787,
|
||||||
QueryToUUID1742922178643,
|
QueryToUUID1742922178643,
|
||||||
NewsletterColumnType1744351418751,
|
NewsletterColumnType1744351418751,
|
||||||
QueryUpdatedAt1744795756230,
|
|
||||||
],
|
],
|
||||||
migrationsRun: true,
|
migrationsRun: true,
|
||||||
migrationsTransactionMode: "each",
|
migrationsTransactionMode: "each",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Column, Entity, PrimaryColumn, UpdateDateColumn } from "typeorm";
|
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class query {
|
export class query {
|
||||||
|
@ -10,7 +10,4 @@ export class query {
|
||||||
|
|
||||||
@Column({ type: "text", default: "" })
|
@Column({ type: "text", default: "" })
|
||||||
query: string;
|
query: string;
|
||||||
|
|
||||||
@UpdateDateColumn()
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ export const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
|
||||||
export const SERVER_PORT = Number(process.env.SERVER_PORT ?? 5000);
|
export const SERVER_PORT = Number(process.env.SERVER_PORT ?? 5000);
|
||||||
|
|
||||||
export const JWT_SECRET = process.env.JWT_SECRET ?? "my_jwt_secret_string_ilughfnadiuhgq§$IUZGFVRweiouarbt1oub3h5q4a";
|
export const JWT_SECRET = process.env.JWT_SECRET ?? "my_jwt_secret_string_ilughfnadiuhgq§$IUZGFVRweiouarbt1oub3h5q4a";
|
||||||
export const JWT_EXPIRATION = (process.env.JWT_EXPIRATION ?? "15m") as ms.StringValue;
|
export const JWT_EXPIRATION = process.env.JWT_EXPIRATION ?? "15m";
|
||||||
export const REFRESH_EXPIRATION = (process.env.REFRESH_EXPIRATION ?? "1d") as ms.StringValue;
|
export const REFRESH_EXPIRATION = process.env.REFRESH_EXPIRATION ?? "1d";
|
||||||
export const PWA_REFRESH_EXPIRATION = (process.env.PWA_REFRESH_EXPIRATION ?? "5d") as ms.StringValue;
|
export const PWA_REFRESH_EXPIRATION = process.env.PWA_REFRESH_EXPIRATION ?? "5d";
|
||||||
|
|
||||||
export const MAIL_USERNAME = process.env.MAIL_USERNAME ?? "";
|
export const MAIL_USERNAME = process.env.MAIL_USERNAME ?? "";
|
||||||
export const MAIL_PASSWORD = process.env.MAIL_PASSWORD ?? "";
|
export const MAIL_PASSWORD = process.env.MAIL_PASSWORD ?? "";
|
||||||
|
@ -30,10 +30,10 @@ export const BACKUP_COPIES = Number(process.env.BACKUP_COPIES ?? "7");
|
||||||
export const BACKUP_AUTO_RESTORE = process.env.BACKUP_AUTO_RESTORE ?? "true";
|
export const BACKUP_AUTO_RESTORE = process.env.BACKUP_AUTO_RESTORE ?? "true";
|
||||||
|
|
||||||
export const USE_SECURITY_STRICT_LIMIT = process.env.USE_SECURITY_STRICT_LIMIT ?? "true";
|
export const USE_SECURITY_STRICT_LIMIT = process.env.USE_SECURITY_STRICT_LIMIT ?? "true";
|
||||||
export const SECURITY_STRICT_LIMIT_WINDOW = (process.env.SECURITY_STRICT_LIMIT_WINDOW ?? "15m") as ms.StringValue;
|
export const SECURITY_STRICT_LIMIT_WINDOW = process.env.SECURITY_STRICT_LIMIT_WINDOW ?? "15m";
|
||||||
export const SECURITY_STRICT_LIMIT_REQUEST_COUNT = Number(process.env.SECURITY_STRICT_LIMIT_REQUEST_COUNT ?? "15");
|
export const SECURITY_STRICT_LIMIT_REQUEST_COUNT = Number(process.env.SECURITY_STRICT_LIMIT_REQUEST_COUNT ?? "15");
|
||||||
export const USE_SECURITY_LIMIT = process.env.USE_SECURITY_LIMIT ?? "true";
|
export const USE_SECURITY_LIMIT = process.env.USE_SECURITY_LIMIT ?? "true";
|
||||||
export const SECURITY_LIMIT_WINDOW = (process.env.SECURITY_LIMIT_WINDOW ?? "1m") as ms.StringValue;
|
export const SECURITY_LIMIT_WINDOW = process.env.SECURITY_LIMIT_WINDOW ?? "1m";
|
||||||
export const SECURITY_LIMIT_REQUEST_COUNT = Number(process.env.SECURITY_LIMIT_REQUEST_COUNT ?? "500");
|
export const SECURITY_LIMIT_REQUEST_COUNT = Number(process.env.SECURITY_LIMIT_REQUEST_COUNT ?? "500");
|
||||||
|
|
||||||
export const TRUST_PROXY = ((): Array<string> | string | boolean | number | null => {
|
export const TRUST_PROXY = ((): Array<string> | string | boolean | number | null => {
|
||||||
|
@ -104,7 +104,7 @@ export function configCheck() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkMS(input: ms.StringValue, origin: string) {
|
function checkMS(input: string, origin: string) {
|
||||||
try {
|
try {
|
||||||
const result = ms(input);
|
const result = ms(input);
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
|
|
|
@ -12,7 +12,6 @@ export default abstract class QueryStoreFactory {
|
||||||
id: record.id,
|
id: record.id,
|
||||||
title: record.title,
|
title: record.title,
|
||||||
query: record.query.startsWith("{") ? JSON.parse(record.query) : record.query,
|
query: record.query.startsWith("{") ? JSON.parse(record.query) : record.query,
|
||||||
updatedAt: record.updatedAt,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -349,12 +349,7 @@ export default abstract class BackupHelper {
|
||||||
"member.birthdate",
|
"member.birthdate",
|
||||||
"member.internalId",
|
"member.internalId",
|
||||||
])
|
])
|
||||||
.addSelect([
|
.addSelect([...(collectIds ? ["query.id"] : []), "recipientsByQuery.title", "recipientsByQuery.query"])
|
||||||
...(collectIds ? ["recipientsByQuery.id"] : []),
|
|
||||||
"recipientsByQuery.title",
|
|
||||||
"recipientsByQuery.query",
|
|
||||||
"recipientsByQuery.updatedAt",
|
|
||||||
])
|
|
||||||
.getMany()
|
.getMany()
|
||||||
.then((res: any) =>
|
.then((res: any) =>
|
||||||
res.map((n: any) => ({
|
res.map((n: any) => ({
|
||||||
|
@ -755,11 +750,11 @@ export default abstract class BackupHelper {
|
||||||
.filter((d) => availableTemplates.includes(d.scope))
|
.filter((d) => availableTemplates.includes(d.scope))
|
||||||
.map((d) => ({
|
.map((d) => ({
|
||||||
...d,
|
...d,
|
||||||
headerHeightId: templates.find((template) => template.template == d.headerHeight)?.id ?? null,
|
headerHeightId: templates.find((template) => template.template == d.headerHeight.template)?.id ?? null,
|
||||||
footerHeightId: templates.find((template) => template.template == d.footerHeight)?.id ?? null,
|
footerHeightId: templates.find((template) => template.template == d.footerHeight.template)?.id ?? null,
|
||||||
headerId: templates.find((template) => template.template == d.header?.template)?.id ?? null,
|
headerId: templates.find((template) => template.template == d.header.template)?.id ?? null,
|
||||||
bodyId: templates.find((template) => template.template == d.body?.template)?.id ?? null,
|
bodyId: templates.find((template) => template.template == d.body.template)?.id ?? null,
|
||||||
footerId: templates.find((template) => template.template == d.footer?.template)?.id ?? null,
|
footerId: templates.find((template) => template.template == d.footer.template)?.id ?? null,
|
||||||
}));
|
}));
|
||||||
availableTemplates.forEach((at) => {
|
availableTemplates.forEach((at) => {
|
||||||
if (!dataWithMappedId.some((d) => d.scope == at)) {
|
if (!dataWithMappedId.some((d) => d.scope == at)) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { Brackets, DataSource, NotBrackets, ObjectLiteral, SelectQueryBuilder, W
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { ConditionStructure, DynamicQueryStructure, FieldType, QueryResult } from "../type/dynamicQueries";
|
import { ConditionStructure, DynamicQueryStructure, FieldType, QueryResult } from "../type/dynamicQueries";
|
||||||
import { TableMeta } from "../type/tableMeta";
|
import { TableMeta } from "../type/tableMeta";
|
||||||
import { StringHelper } from "./stringHelper";
|
|
||||||
|
|
||||||
export default abstract class DynamicQueryBuilder {
|
export default abstract class DynamicQueryBuilder {
|
||||||
public static allowedTables: Array<string> = [
|
public static allowedTables: Array<string> = [
|
||||||
|
@ -63,18 +62,11 @@ export default abstract class DynamicQueryBuilder {
|
||||||
count?: number;
|
count?: number;
|
||||||
noLimit?: boolean;
|
noLimit?: boolean;
|
||||||
}): SelectQueryBuilder<ObjectLiteral> {
|
}): SelectQueryBuilder<ObjectLiteral> {
|
||||||
let affix = queryObj.id ?? StringHelper.random(10);
|
let affix = Math.random().toString(36).substring(2);
|
||||||
let query = dataSource.getRepository(queryObj.table).createQueryBuilder(`${affix}_${queryObj.table}`);
|
let query = dataSource.getRepository(queryObj.table).createQueryBuilder(`${queryObj.table}_${affix}`);
|
||||||
|
|
||||||
this.buildDynamicQuery(query, queryObj, affix);
|
this.buildDynamicQuery(query, queryObj, affix);
|
||||||
|
|
||||||
if (queryObj.orderBy) {
|
|
||||||
queryObj.orderBy.forEach((order) => {
|
|
||||||
// compatability layer for none id (old) queries
|
|
||||||
if (order.id) query.addOrderBy(`${order.id}_${order.table}.${order.column}`, order.order);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!noLimit) {
|
if (!noLimit) {
|
||||||
query.offset(offset);
|
query.offset(offset);
|
||||||
query.limit(count);
|
query.limit(count);
|
||||||
|
@ -86,10 +78,10 @@ export default abstract class DynamicQueryBuilder {
|
||||||
private static buildDynamicQuery(
|
private static buildDynamicQuery(
|
||||||
query: SelectQueryBuilder<ObjectLiteral>,
|
query: SelectQueryBuilder<ObjectLiteral>,
|
||||||
queryObject: DynamicQueryStructure,
|
queryObject: DynamicQueryStructure,
|
||||||
affix: string = "", // table id
|
affix: string = "",
|
||||||
depth: number = 0
|
depth: number = 0
|
||||||
): void {
|
): void {
|
||||||
const alias = `${affix}_${queryObject.table}`;
|
const alias = queryObject.table + "_" + affix;
|
||||||
let firstSelect = true;
|
let firstSelect = true;
|
||||||
let selects: Array<string> = [];
|
let selects: Array<string> = [];
|
||||||
|
|
||||||
|
@ -116,21 +108,18 @@ export default abstract class DynamicQueryBuilder {
|
||||||
|
|
||||||
if (queryObject.join) {
|
if (queryObject.join) {
|
||||||
for (const join of queryObject.join) {
|
for (const join of queryObject.join) {
|
||||||
let subaffix = join.id ?? StringHelper.random(10);
|
let subaffix = Math.random().toString(36).substring(2);
|
||||||
if (join.type == undefined) join.type = "defined";
|
query.leftJoin(`${alias}.${join.foreignColumn}`, join.table + "_" + subaffix);
|
||||||
if (join.type == "defined") {
|
|
||||||
query.innerJoin(`${alias}.${join.foreignColumn}`, `${subaffix}_${join.table}`);
|
|
||||||
} else {
|
|
||||||
let condition = join.condition
|
|
||||||
.replaceAll(`${join.table}.`, `${subaffix}_${join.table}.`)
|
|
||||||
.replaceAll(`${queryObject.table}.`, `${alias}.`);
|
|
||||||
|
|
||||||
query.innerJoin(join.table, `${subaffix}_${join.table}`, condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.buildDynamicQuery(query, join, subaffix, depth + 1);
|
this.buildDynamicQuery(query, join, subaffix, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (queryObject.orderBy) {
|
||||||
|
queryObject.orderBy.forEach((order) => {
|
||||||
|
query.addOrderBy(`${alias}.${order.column}`, order.order);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static applyWhere(
|
public static applyWhere(
|
||||||
|
@ -177,7 +166,7 @@ export default abstract class DynamicQueryBuilder {
|
||||||
condition: ConditionStructure & { structureType: "condition" },
|
condition: ConditionStructure & { structureType: "condition" },
|
||||||
alias: string
|
alias: string
|
||||||
): { query: string; parameters: Record<string, unknown> } {
|
): { query: string; parameters: Record<string, unknown> } {
|
||||||
const parameterKey = `${condition.column}_${Math.random().toString(36).substring(2)}`;
|
const parameterKey = `${alias}_${condition.column}_${Math.random().toString(36).substring(2)}`;
|
||||||
let query = `${alias}.${condition.column}`;
|
let query = `${alias}.${condition.column}`;
|
||||||
let parameters: Record<string, unknown> = {};
|
let parameters: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
@ -390,7 +379,6 @@ export default abstract class DynamicQueryBuilder {
|
||||||
count: noLimit ? total : count,
|
count: noLimit ? total : count,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return {
|
return {
|
||||||
stats: "error",
|
stats: "error",
|
||||||
sql: error.sql,
|
sql: error.sql,
|
||||||
|
@ -403,31 +391,27 @@ export default abstract class DynamicQueryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberQuery: DynamicQueryStructure = {
|
const memberQuery: DynamicQueryStructure = {
|
||||||
id: "memberId",
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "member",
|
table: "member",
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{ id: "memberId", depth: 0, table: "member", column: "lastname", order: "ASC" },
|
{ column: "lastname", order: "ASC" },
|
||||||
{ id: "memberId", depth: 0, table: "member", column: "firstname", order: "ASC" },
|
{ column: "firstname", order: "ASC" },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const memberByRunningMembershipQuery: DynamicQueryStructure = {
|
const memberByRunningMembershipQuery: DynamicQueryStructure = {
|
||||||
id: "memberId",
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "member",
|
table: "member",
|
||||||
join: [
|
join: [
|
||||||
{
|
{
|
||||||
id: "membershipId",
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "membership",
|
table: "membership",
|
||||||
where: [{ structureType: "condition", concat: "_", operation: "null", column: "end", value: "" }],
|
where: [{ structureType: "condition", concat: "_", operation: "null", column: "end", value: "" }],
|
||||||
foreignColumn: "memberships",
|
foreignColumn: "memberships",
|
||||||
type: "defined",
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{ id: "memberId", depth: 0, table: "member", column: "lastname", order: "ASC" },
|
{ column: "lastname", order: "ASC" },
|
||||||
{ id: "memberId", depth: 0, table: "member", column: "firstname", order: "ASC" },
|
{ column: "firstname", order: "ASC" },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
|
||||||
import { getTypeByORM, getDefaultByORM } from "./ormHelper";
|
|
||||||
|
|
||||||
export class QueryUpdatedAt1744795756230 implements MigrationInterface {
|
|
||||||
name = "QueryUpdatedAt1744795756230";
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.addColumn(
|
|
||||||
"query",
|
|
||||||
new TableColumn({
|
|
||||||
name: "updatedAt",
|
|
||||||
...getTypeByORM("datetime", false, 6),
|
|
||||||
default: getDefaultByORM("currentTimestamp", 6),
|
|
||||||
onUpdate: getDefaultByORM<string>("currentTimestamp", 6),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumn("query", "updatedAt");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,5 @@
|
||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
import {
|
import { executeQuery, getAllTableMeta, getTableMetaByTablename } from "../../../controller/admin/club/queryBuilderController";
|
||||||
executeQuery,
|
|
||||||
executeQueryByStoreId,
|
|
||||||
getAllTableMeta,
|
|
||||||
getTableMetaByTablename,
|
|
||||||
} from "../../../controller/admin/club/queryBuilderController";
|
|
||||||
|
|
||||||
var router = express.Router({ mergeParams: true });
|
var router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
|
@ -20,8 +15,4 @@ router.post("/query", async (req: Request, res: Response) => {
|
||||||
await executeQuery(req, res);
|
await executeQuery(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/query/:storeId", async (req: Request, res: Response) => {
|
|
||||||
await executeQueryByStoreId(req, res);
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -68,7 +68,7 @@ export default (app: Express) => {
|
||||||
}
|
}
|
||||||
app.set("query parser", "extended");
|
app.set("query parser", "extended");
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.options("*splat", cors());
|
app.options("*", cors());
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
app.use(morgan("short"));
|
app.use(morgan("short"));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
export interface DynamicQueryStructure {
|
export interface DynamicQueryStructure {
|
||||||
id: string;
|
|
||||||
select: string[] | "*";
|
select: string[] | "*";
|
||||||
table: string;
|
table: string;
|
||||||
where?: Array<ConditionStructure>;
|
where?: Array<ConditionStructure>;
|
||||||
join?: Array<DynamicQueryStructure & JoinStructure>;
|
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
||||||
orderBy?: Array<OrderByStructure>; // only at top level
|
orderBy?: Array<OrderByStructure>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConditionStructure = (
|
export type ConditionStructure = (
|
||||||
|
@ -48,12 +47,7 @@ export type WhereOperation =
|
||||||
| "timespanEq"; // Date before x years (YYYY-01-01 <bis> YYYY-12-31)
|
| "timespanEq"; // Date before x years (YYYY-01-01 <bis> YYYY-12-31)
|
||||||
// TODO: age between | age equals | age greater | age smaller
|
// TODO: age between | age equals | age greater | age smaller
|
||||||
|
|
||||||
export type JoinStructure = { foreignColumn: string; type: "defined" } | { condition: string; type: "custom" };
|
|
||||||
|
|
||||||
export type OrderByStructure = {
|
export type OrderByStructure = {
|
||||||
id: string;
|
|
||||||
depth: number;
|
|
||||||
table: string;
|
|
||||||
column: string;
|
column: string;
|
||||||
order: OrderByType;
|
order: OrderByType;
|
||||||
};
|
};
|
||||||
|
@ -65,7 +59,6 @@ export type QueryResult = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const exampleQuery: DynamicQueryStructure = {
|
export const exampleQuery: DynamicQueryStructure = {
|
||||||
id: "1234",
|
|
||||||
select: ["firstname", "lastname"],
|
select: ["firstname", "lastname"],
|
||||||
table: "member",
|
table: "member",
|
||||||
where: [
|
where: [
|
||||||
|
@ -99,25 +92,19 @@ export const exampleQuery: DynamicQueryStructure = {
|
||||||
],
|
],
|
||||||
join: [
|
join: [
|
||||||
{
|
{
|
||||||
id: "5678",
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "communication",
|
table: "communication",
|
||||||
foreignColumn: "sendNewsletter",
|
foreignColumn: "sendNewsletter",
|
||||||
type: "defined",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "91011",
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "membership",
|
table: "membership",
|
||||||
foreignColumn: "memberships",
|
foreignColumn: "memberships",
|
||||||
type: "defined",
|
|
||||||
join: [
|
join: [
|
||||||
{
|
{
|
||||||
id: "121314",
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "membership_status",
|
table: "membership_status",
|
||||||
foreignColumn: "status",
|
foreignColumn: "status",
|
||||||
type: "defined",
|
|
||||||
where: [
|
where: [
|
||||||
{
|
{
|
||||||
structureType: "condition",
|
structureType: "condition",
|
||||||
|
@ -133,16 +120,10 @@ export const exampleQuery: DynamicQueryStructure = {
|
||||||
],
|
],
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{
|
{
|
||||||
id: "1234",
|
|
||||||
depth: 0,
|
|
||||||
table: "member",
|
|
||||||
column: "firstname",
|
column: "firstname",
|
||||||
order: "ASC",
|
order: "ASC",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "1234",
|
|
||||||
depth: 0,
|
|
||||||
table: "member",
|
|
||||||
column: "lastname",
|
column: "lastname",
|
||||||
order: "ASC",
|
order: "ASC",
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,5 +4,4 @@ export interface QueryStoreViewModel {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
query: string | DynamicQueryStructure;
|
query: string | DynamicQueryStructure;
|
||||||
updatedAt: Date;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue