@opengis/fastify-table 2.0.154 → 2.0.155

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 +1 @@
1
- {"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/insert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAqLjE"}
1
+ {"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/insert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAyMjE"}
@@ -130,6 +130,17 @@ export default async function insert(req, reply) {
130
130
  if (!res) {
131
131
  return reply.status(400).send({ error: "nothing added", code: 400 });
132
132
  }
133
+ const pk = pg.pk?.[loadTemplate?.table || table];
134
+ const id = res[pk];
135
+ if (Array.isArray(body.files)) {
136
+ await Promise.all(body.files
137
+ .filter((el) => el.file_id && el.file_path)
138
+ .map(async (el) => pg.query("update crm.files set entity_id=$1 where entity_id = 'uploads' and file_id=$2 and file_path=$3", [id, el.file_id, el.file_path])));
139
+ }
140
+ // remove stale files
141
+ // await pg.query(
142
+ // "delete from crm.files where entity_id = 'uploads' and cdate < now() - interval '1 day'"
143
+ // );
133
144
  // admin.custom_column
134
145
  await applyHook("afterInsert", {
135
146
  pg,
@@ -139,8 +150,7 @@ export default async function insert(req, reply) {
139
150
  payload: res,
140
151
  user,
141
152
  });
142
- const pk = pg.pk?.[loadTemplate?.table || table];
143
153
  return reply
144
154
  .status(200)
145
- .send({ id: res?.rows?.[0]?.[pk], rows: res.rows, extra: res.extra, ...(res.rows?.[0] || {}) });
155
+ .send({ id, rows: res.rows, extra: res.extra, ...(res || {}) });
146
156
  }
@@ -1 +1 @@
1
- {"version":3,"file":"widget.get.d.ts","sourceRoot":"","sources":["../../../../../server/routes/widget/controllers/widget.get.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AAEH,wBAA8B,SAAS,CACrC,EAAE,EAAqB,EAAE,IAAS,EAAE,MAAW,EAAE,KAAU,EAAE,EAAE,GAAG,EAClE,KAAK,EAAE,GAAG,gBA+KX"}
1
+ {"version":3,"file":"widget.get.d.ts","sourceRoot":"","sources":["../../../../../server/routes/widget/controllers/widget.get.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AAEH,wBAA8B,SAAS,CACrC,EAAE,EAAqB,EAAE,IAAS,EAAE,MAAW,EAAE,KAAU,EAAE,EAAE,GAAG,EAClE,KAAK,EAAE,GAAG,gBAyLX"}
@@ -124,7 +124,9 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
124
124
  !process.env.VITEST) {
125
125
  return reply.status(404).send("log table not found");
126
126
  }
127
- const q1 = `select ${username} as author, u.login, a.cdate, a.editor_date from ${tableName} a
127
+ const cdateColumn = columns.find((col) => ["cdate", "created_at"].includes(col.name))?.name;
128
+ const editorDateColumn = columns.find((col) => ["editor_date", "updated_at"].includes(col.name))?.name;
129
+ const q1 = `select ${username} as author, u.login ${cdateColumn ? `,a.${cdateColumn} as cdate` : ""} ${editorDateColumn ? `,a.${editorDateColumn} as editor_date` : ""} from ${tableName} a
128
130
  left join admin.users u on a.${authorIdColumn}=u.uid where a.${pk}=$1 limit 1`;
129
131
  const data = pg.pk["admin.users"] && pk && tableName
130
132
  ? await pg
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.154",
3
+ "version": "2.0.155",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [