@opengis/admin 0.3.64 → 0.3.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { _ as n, e as m } from "./import-file-DRzOvv7x.js";
1
+ import { _ as n, e as m } from "./import-file-Dt2mnHAW.js";
2
2
  import { u as p } from "./user-B_2kh6ic.js";
3
3
  import { resolveComponent as d, createElementBlock as f, openBlock as u, createElementVNode as o, createBlock as h, createCommentVNode as b } from "vue";
4
4
  const x = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.3.64",
3
+ "version": "0.3.66",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -46,9 +46,9 @@
46
46
  "@fullcalendar/list": "^6.1.15",
47
47
  "@fullcalendar/timegrid": "^6.1.15",
48
48
  "@fullcalendar/vue3": "^6.1.15",
49
- "@opengis/fastify-auth": "^1.0.73",
50
- "@opengis/fastify-file": "^1.0.42",
51
- "@opengis/fastify-table": "^1.2.98",
49
+ "@opengis/fastify-auth": "1.0.80",
50
+ "@opengis/fastify-file": "1.0.66",
51
+ "@opengis/fastify-table": "1.3.25",
52
52
  "@opengis/v3-core": "^0.3.126",
53
53
  "@opengis/v3-filter": "^0.0.72",
54
54
  "@tiptap/core": "^2.8.0",
@@ -6,26 +6,20 @@ import { pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/
6
6
 
7
7
  export default async function getSettingsApp({
8
8
  pg = pgClients.client,
9
- }) {
9
+ }, reply) {
10
10
  const time = Date.now();
11
+
11
12
  if (!pg.pk?.[table]) {
12
- return { message: 'table not found', status: 404 };
13
+ return reply.status(404).send('table not found');
13
14
  }
14
15
 
15
- /*const keyCache = `${pg.options?.database}:settings:${params?.key || 'all'}:${query?.json ? 'json' : 'plain'}:${table}`;
16
- const cache = await redis.get(keyCache);
17
-
18
- if (cache && !config?.local) {
19
- return JSON.parse(cache);
20
- }*/
16
+ const { rows = [] } = await pg.query('select property_key as key, property_text, property_json from admin.properties');
21
17
 
22
- const { rows } = await pgClients.client.query("select property_key as key,property_text as val from admin.properties /*where property_key~'^(site|map)'*/");
23
- const settings = rows.reduce((p, { key, val }) => { const [k1, k2] = key.split('.'); p[k1] = p[k1] || {}; p[k1][k2] = val; return p }, {});
24
- const settings1 = rows.reduce((p, { key, val }) => ({ ...p, [key]: val }), {});
18
+ const settings = rows.reduce((acc, { key, property_text, property_json }) => ({ ...acc, [key]: property_text || property_json }), {});
25
19
 
26
20
  const forms = await Promise.all(getTemplatePath('setting')
27
21
  .map(async (el) => ({ name: el[0], body: await getTemplate('setting', el[0]) }))
28
22
  );
29
23
 
30
- return { message: { time: Date.now() - time, forms, settings: settings1 }, status: 200 };
24
+ return reply.status(200).send({ time: Date.now() - time, forms, settings });
31
25
  }
@@ -1,6 +1,6 @@
1
1
  const table = 'admin.properties';
2
2
 
3
- import { dataInsert } from '@opengis/fastify-table/utils.js';
3
+ import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
4
4
 
5
5
  function checkValueType(val) {
6
6
  if (val) {
@@ -15,28 +15,34 @@ function checkValueType(val) {
15
15
  }
16
16
 
17
17
  export default async function postSettingsApp({
18
- pg, user = {}, body = {}, uid
19
- }) {
18
+ pg = pgClients.client, body = {}, user = {}, uid = user?.uid,
19
+ }, reply) {
20
20
  if (!user?.user_type?.includes?.('admin')) {
21
- return { message: 'access restricted', status: 403 };
21
+ return reply.status(403).send('access restricted');
22
22
  }
23
23
  const { key, val } = body;
24
+
24
25
  if ((!key || !val) && !Object.keys(body).length) {
25
- return { message: 'not enough params', status: 400 };
26
+ return reply.status(400).send('not enough body params');
26
27
  }
27
28
 
28
29
  if (!pg?.pk?.[table]) {
29
- return { message: 'table not found', status: 404 };
30
+ return reply.status(404).send('table not found');
30
31
  }
32
+
31
33
  const keys = Object.keys(body);
32
34
  await pg.query(`delete from ${table} where property_key=any($1)`, [keys]);
33
35
 
34
- await Promise.all(keys.map(async (el) => {
35
- const columnType = table === 'admin.user_properties' ? 'property_json' : checkValueType(body[el]);
36
- const data = { property_key: el, [columnType]: body[el], uid };
37
- if (!body[el]) return;
36
+ await Promise.all(keys.filter(el => body[el]).map(async (el) => {
37
+ const columnType = table === 'admin.user_properties'
38
+ ? 'property_json'
39
+ : checkValueType(body[el]);
40
+
38
41
  await dataInsert({
39
- pg, table, data, uid,
42
+ pg,
43
+ table,
44
+ data: { property_key: el, [columnType]: body[el] },
45
+ uid,
40
46
  });
41
47
 
42
48
  }));