From 42a1c9fe1a14a6b7a7abd4071fd48019e9989381 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 10:25:51 +0200 Subject: [PATCH 01/10] set proper response status for creation --- server/utils/baaPagination.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index 6920cc4..810eff4 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -1,4 +1,4 @@ -/* global defineEventHandler, getQuery, createError, readBody */ +/* global defineEventHandler, getQuery, createError, readBody, setResponseStatus */ import { QueryObject } from "ufo"; import { H3Event } from "h3"; import { ResultSetHeader } from "mysql2/promise"; @@ -146,6 +146,8 @@ export default class BaaPagination Date: Thu, 11 May 2023 10:27:24 +0200 Subject: [PATCH 02/10] fix typos, fix logic of "around" --- server/utils/baaPagination.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index 810eff4..dc80ff5 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -74,17 +74,18 @@ export default class BaaPagination ? ORDER BY \`${this.key}\` DESC LIMIT ?`, + `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ORDER BY \`${this.key}\` DESC LIMIT ?`, [queryType.id, limit], ) as unknown as data; return data; } case "around": { const [data] = await database.query( - `(SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + + ` SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + "UNION ALL\n" + - `(SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` < ? ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + - "ORDER BY `id` DESC", + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` < ? ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + + `) as \`x\` ORDER BY \`${this.key}\` DESC`, [queryType.id, Math.ceil(limit / 2), queryType.id, Math.floor(limit / 2)], ) as unknown as data; return data; From 7c2ca8bbe44de308d7efa19f4b6492fe979bf7ec Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 10:43:05 +0200 Subject: [PATCH 03/10] add where arguments --- server/utils/baaPagination.ts | 41 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index dc80ff5..76bf4cc 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -63,37 +63,40 @@ export default class BaaPagination = [], ) { + const sqlwhere = where ? `AND (${where})` : ""; switch (queryType.type) { case "before": { const [data] = await database.query( - `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` < ? ORDER BY \`${this.key}\` DESC LIMIT ?`, - [queryType.id, limit], + `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, + [queryType.id, ...bind, limit], ) as unknown as data; return data; } case "after": { const [data] = await database.query( - `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ORDER BY \`${this.key}\` DESC LIMIT ?`, - [queryType.id, limit], + `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, + [queryType.id, ...bind, limit], ) as unknown as data; return data; } case "around": { const [data] = await database.query( ` SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + - `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ${sqlwhere} ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + "UNION ALL\n" + - `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` < ? ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + `) as \`x\` ORDER BY \`${this.key}\` DESC`, - [queryType.id, Math.ceil(limit / 2), queryType.id, Math.floor(limit / 2)], + [queryType.id, ...bind, Math.ceil(limit / 2), queryType.id, ...bind, Math.floor(limit / 2)], ) as unknown as data; return data; } case null: { const [data] = await database.query( - `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` ORDER BY \`${this.key}\` DESC LIMIT ?`, - [limit], + `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE TRUE ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, + [...bind, limit], ) as unknown as data; return data; } @@ -102,7 +105,13 @@ export default class BaaPagination = [], + ) { const query = getQuery(e); let limit = defaultLimit; @@ -122,7 +131,7 @@ export default class BaaPagination>( @@ -217,9 +226,15 @@ export default class BaaPagination = [], + ) { + const sqlwhere = where ? `WHERE ${where}` : ""; const [[data]] = await database.query( - `SELECT COUNT(*) as \`count\` FROM \`${this.table}\``, + `SELECT COUNT(*) as \`count\` FROM \`${this.table}\` ${sqlwhere}`, + bind, ) as data<{count: number}>; if (!data) throw createError("Database returned no rows"); From 6d4cbbd1b2246c9d63b3b6d90ec50e77fb8644b4 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 10:49:47 +0200 Subject: [PATCH 04/10] fixup --- server/utils/baaPagination.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index 76bf4cc..ea3cd0f 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -148,7 +148,7 @@ export default class BaaPagination body[field])); await database.query( - "INSERT INTO `clients` " + + `INSERT INTO \`${this.table}\` ` + `(\`${this.key}\`,\`${fields.join("`, `")}\`) ` + "VALUES (" + "?, ".repeat(fields.length) + From b14cf774ec8a557d2b9d3ce6b2e06e99e5dfe327 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 10:51:41 +0200 Subject: [PATCH 05/10] allow select modification --- server/utils/baaPagination.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index ea3cd0f..6978a6a 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -21,6 +21,7 @@ type queryType = { export default class BaaPagination { readonly table: string; readonly key: keyType; + readonly select: string; /** * Gets queryType for a given query with a value @@ -70,24 +71,24 @@ export default class BaaPagination; return data; } case "after": { const [data] = await database.query( - `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, + `SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, [queryType.id, ...bind, limit], ) as unknown as data; return data; } case "around": { const [data] = await database.query( - ` SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + + ` SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ${sqlwhere} ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + "UNION ALL\n" + - `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + + `(SELECT ${this.select} FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + `) as \`x\` ORDER BY \`${this.key}\` DESC`, [queryType.id, ...bind, Math.ceil(limit / 2), queryType.id, ...bind, Math.floor(limit / 2)], ) as unknown as data; @@ -95,7 +96,7 @@ export default class BaaPagination; return data; @@ -167,7 +168,7 @@ export default class BaaPagination; @@ -206,7 +207,7 @@ export default class BaaPagination; @@ -241,8 +242,9 @@ export default class BaaPagination Date: Thu, 11 May 2023 11:02:08 +0200 Subject: [PATCH 06/10] fixup where --- server/utils/baaPagination.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index 6978a6a..e230763 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -67,7 +67,7 @@ export default class BaaPagination = [], ) { - const sqlwhere = where ? `AND (${where})` : ""; + const sqlwhere = where !== "" ? `AND (${where})` : ""; switch (queryType.type) { case "before": { const [data] = await database.query( @@ -232,7 +232,7 @@ export default class BaaPagination = [], ) { - const sqlwhere = where ? `WHERE ${where}` : ""; + const sqlwhere = where !== "" ? `WHERE ${where}` : ""; const [[data]] = await database.query( `SELECT COUNT(*) as \`count\` FROM \`${this.table}\` ${sqlwhere}`, bind, From 7a9e45173940eb376d46d0da6819046542369ce7 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 11:09:28 +0200 Subject: [PATCH 07/10] add groupBy --- server/utils/baaPagination.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index e230763..4155145 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -22,6 +22,11 @@ export default class BaaPagination; return data; } case "after": { const [data] = await database.query( - `SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, + `SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC ${this.sqlGroupBy} LIMIT ?`, [queryType.id, ...bind, limit], ) as unknown as data; return data; @@ -86,9 +91,9 @@ export default class BaaPagination= ? ${sqlwhere} ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ${sqlwhere} ORDER BY \`${this.key}\` ${this.sqlGroupBy} ASC LIMIT ?)\n` + "UNION ALL\n" + - `(SELECT ${this.select} FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + + `(SELECT ${this.select} FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC ${this.sqlGroupBy} LIMIT ?)\n` + `) as \`x\` ORDER BY \`${this.key}\` DESC`, [queryType.id, ...bind, Math.ceil(limit / 2), queryType.id, ...bind, Math.floor(limit / 2)], ) as unknown as data; @@ -96,7 +101,7 @@ export default class BaaPagination; return data; @@ -234,7 +239,7 @@ export default class BaaPagination; @@ -242,9 +247,15 @@ export default class BaaPagination Date: Wed, 24 May 2023 09:40:45 +0200 Subject: [PATCH 08/10] update cuz presentation --- components/alerts.vue | 63 +++++++ components/entryEditor.vue | 51 ++++++ components/navigation/navigation.vue | 8 +- components/orderView.vue | 56 ++++++ components/pagedList.vue | 2 + components/pagedTable.vue | 4 + pages/client/[id].vue | 171 +++++++++++++++-- pages/clients.vue | 127 ++++++++++--- pages/index.vue | 3 +- pages/login.vue | 7 + server/api/clients/[id]/orders.get.ts | 9 + server/api/login.post.ts | 2 +- server/api/orders.get.ts | 37 ++++ server/api/orders.post.ts | 172 ++++++++++++++++++ server/api/orders/[id].delete.ts | 17 ++ server/api/orders/[id].get.ts | 108 +++++++++++ server/api/orders/[id].patch.ts | 17 ++ .../api/orders/[id]/imported_products.get.ts | 12 ++ .../api/orders/[id]/imported_products.post.ts | 27 +++ server/api/orders/[id]/work.get.ts | 12 ++ server/api/orders/[id]/work.post.ts | 28 +++ .../api/orders/[id]/work/[idWork].delete.ts | 20 ++ server/api/orders/[id]/work/[idWork].get.ts | 11 ++ server/utils/baaPagination.ts | 2 +- server/utils/database.ts | 12 +- server/utils/getRequestingUser.ts | 25 +++ server/utils/validation.ts | 31 ++++ {server/utils => utils}/snowflake.ts | 10 +- utils/types/database.ts | 109 +++++++---- 29 files changed, 1065 insertions(+), 88 deletions(-) create mode 100644 components/alerts.vue create mode 100644 components/entryEditor.vue create mode 100644 components/orderView.vue create mode 100644 server/api/clients/[id]/orders.get.ts create mode 100644 server/api/orders.get.ts create mode 100644 server/api/orders.post.ts create mode 100644 server/api/orders/[id].delete.ts create mode 100644 server/api/orders/[id].get.ts create mode 100644 server/api/orders/[id].patch.ts create mode 100644 server/api/orders/[id]/imported_products.get.ts create mode 100644 server/api/orders/[id]/imported_products.post.ts create mode 100644 server/api/orders/[id]/work.get.ts create mode 100644 server/api/orders/[id]/work.post.ts create mode 100644 server/api/orders/[id]/work/[idWork].delete.ts create mode 100644 server/api/orders/[id]/work/[idWork].get.ts create mode 100644 server/utils/getRequestingUser.ts create mode 100644 server/utils/validation.ts rename {server/utils => utils}/snowflake.ts (86%) diff --git a/components/alerts.vue b/components/alerts.vue new file mode 100644 index 0000000..1301eab --- /dev/null +++ b/components/alerts.vue @@ -0,0 +1,63 @@ + + + + + diff --git a/components/entryEditor.vue b/components/entryEditor.vue new file mode 100644 index 0000000..49a0651 --- /dev/null +++ b/components/entryEditor.vue @@ -0,0 +1,51 @@ + + + diff --git a/components/navigation/navigation.vue b/components/navigation/navigation.vue index 02ee1f2..c72c67d 100644 --- a/components/navigation/navigation.vue +++ b/components/navigation/navigation.vue @@ -13,18 +13,20 @@ const navOpen = ref(!mobile.value); Database Project - + - + + + diff --git a/components/orderView.vue b/components/orderView.vue new file mode 100644 index 0000000..aa540b7 --- /dev/null +++ b/components/orderView.vue @@ -0,0 +1,56 @@ + + + diff --git a/components/pagedList.vue b/components/pagedList.vue index 952a2c7..24dc5ed 100644 --- a/components/pagedList.vue +++ b/components/pagedList.vue @@ -2,6 +2,7 @@ const props = defineProps<{ records: Array, recordKey: string, + recordValue?: string, variant?: "default" | "inset" | "accordion" | "popout", modelValue?: any, }>(); @@ -22,6 +23,7 @@ defineEmits<{ v-for="record in records" :key="record[recordKey]" :variant="props.variant ?? 'default'" + :value="recordValue !== undefined ? record[recordValue] : undefined" >