@opengis/fastify-table 2.0.54 → 2.0.56

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":"checkPolicy.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAKhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,oSA6K5E"}
1
+ {"version":3,"file":"checkPolicy.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAKhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,oSA8K5E"}
@@ -22,7 +22,8 @@ export default function checkPolicy(req, reply) {
22
22
  config.admin ||
23
23
  hostname.startsWith("admin");
24
24
  const { role, referer, policy = [], } = (routeOptions?.config || {});
25
- const isRole = (role && user?.user_type !== role) ||
25
+ // role=admin|regular
26
+ const isRole = (role && (!user?.user_type || !role?.includes?.(user?.user_type))) ||
26
27
  (policy.includes("admin") && user?.user_type !== "admin");
27
28
  const allowExtPublic = [".png", ".jpg", ".svg"];
28
29
  const ext = path.toLowerCase().substr(-4);
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA0B5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,IAAI,EACJ,QAAQ,EACR,OAAO,EAAE,QAAQ,EACjB,GAAG,EACH,KAAU,EACV,IAAkB,EAClB,QAAQ,EACR,UAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,KAAK,EAAE,YAAY,gBAmVpB"}
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA0B5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,IAAI,EACJ,QAAQ,EACR,OAAO,EAAE,QAAQ,EACjB,GAAG,EACH,KAAU,EACV,IAAkB,EAClB,QAAQ,EACR,UAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,KAAK,EAAE,YAAY,gBAgWpB"}
@@ -51,7 +51,7 @@ export default async function exportTable({ pg = pgClients.client, user, unittes
51
51
  return reply.status(400).send("param format is invalid");
52
52
  }
53
53
  const date = new Date();
54
- const sufixName = `${filter}-${cols || "all"}-${search}-${query.limit || "unlimited"}`;
54
+ const sufixName = `${filter}-${cols || "all"}-${search}-${query.limit || "unlimited"}-${id}`;
55
55
  const sufixDate = [
56
56
  date.getFullYear(),
57
57
  date.getMonth(),
@@ -91,7 +91,8 @@ export default async function exportTable({ pg = pgClients.client, user, unittes
91
91
  }
92
92
  const loadTable = await getTemplate("table", table);
93
93
  const meta = await getMeta({ pg, table: loadTable?.table || table });
94
- if (!meta?.pk && !meta?.view && !tableSql) {
94
+ const viewSql = await getTemplate("view", loadTable?.table || table);
95
+ if (!meta?.pk && !meta?.view && !tableSql && !viewSql) {
95
96
  return reply.status(404).send("table not found");
96
97
  }
97
98
  if (format === "geojson" && !meta?.geom) {
@@ -110,9 +111,11 @@ export default async function exportTable({ pg = pgClients.client, user, unittes
110
111
  sufix: false,
111
112
  };
112
113
  // check total count, debug sql etc.
113
- const result = tableSql
114
+ const result = tableSql || viewSql
114
115
  ? await pg
115
- .query(`select count(*) as total, json_agg(row_to_json(q)) as rows from (${tableSql})q`)
116
+ .query(`select count(*) as total, json_agg(row_to_json(q)) as rows from (${tableSql || viewSql})q where ${loadTable?.key && id
117
+ ? `${loadTable?.key}::text = '${id}'`
118
+ : "true"}`)
116
119
  .then((el) => el.rows?.[0] || {})
117
120
  : await getData(options, reply, true);
118
121
  if (sql)
@@ -174,8 +177,10 @@ export default async function exportTable({ pg = pgClients.client, user, unittes
174
177
  while (+filtered - offset > 0 && !res?.error) {
175
178
  try {
176
179
  send(`Оброблено: ${offset}/${filtered}`);
177
- const { rows = [] } = tableSql
178
- ? await pg.query(`select * from (${tableSql})q limit ${options.limit} offset ${offset}`)
180
+ const { rows = [] } = tableSql || viewSql
181
+ ? await pg.query(`select * from (${tableSql || viewSql})q where ${loadTable?.key && id
182
+ ? `${loadTable?.key}::text = '${id}'`
183
+ : "true"} limit ${options.limit} offset ${offset}`)
179
184
  : await getData({ ...options, page }, reply, true);
180
185
  send(`seq: ${++seq}`);
181
186
  send(`Обробка ${rows.length} об'єктів...`);
@@ -1 +1 @@
1
- {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA4DzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,EACD,KAAK,EAAE,YAAY,EACnB,MAAM,CAAC,EAAE,GAAG,gBAgzBb"}
1
+ {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA4DzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,EACD,KAAK,EAAE,YAAY,EACnB,MAAM,CAAC,EAAE,GAAG,gBAwzBb"}
@@ -137,13 +137,16 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
137
137
  user,
138
138
  }, null)) || {};
139
139
  const tableMeta = await getMeta({ pg, table: table1 });
140
+ const viewSql = await getTemplate("view", table1);
140
141
  timeArr.push(Date.now());
141
142
  if (tableMeta?.view) {
142
143
  if (!loadTable?.key && !tokenData?.key)
143
144
  return { message: `key not found: ${table1}`, status: 404 };
144
145
  Object.assign(tableMeta, { pk: loadTable?.key || tokenData?.key });
145
146
  }
146
- const { pk, columns: dbColumns = [] } = tableMeta || {};
147
+ const { pk, columns: dbColumns = [] } = (viewSql
148
+ ? { pk: loadTable?.key, columns: loadTable?.columns }
149
+ : tableMeta) || {};
147
150
  const columns1 = columns ||
148
151
  dbColumns.map(({ name, title, dataTypeID }) => ({
149
152
  name,
@@ -176,9 +179,9 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
176
179
  ?.filter?.((el) => el.inline)
177
180
  ?.map((el) => `,(${el.sql})`)
178
181
  ?.join("") || "";
179
- const { fields = [] } = pg.queryCache
180
- ? await pg.queryCache(`select * ${sqlInline} from ${table1} t ${sqlTable} ${cardSqlTable} limit 0`)
181
- : {};
182
+ const { fields = [] } = !viewSql
183
+ ? await pg.query(`select * ${sqlInline} from ${table1} t ${sqlTable} ${cardSqlTable} limit 0`)
184
+ : await pg.query(`select * from (${viewSql})q limit 0`);
182
185
  const dbColumnsTable = fields.map((el) => el.name);
183
186
  const cols = columns
184
187
  .filter((el) => el.name !== "geom" && dbColumnsTable.includes(el.name))
@@ -295,7 +298,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
295
298
  from (select * ${sql
296
299
  ?.filter((el) => el.inline)
297
300
  .map((el) => `,(${el.sql})`)
298
- .join("") || ""} from ${table1} t ${sqlTable} ) t
301
+ .join("") || ""} from ${viewSql ? `(${viewSql})` : table1} t ${sqlTable} ) t
299
302
 
300
303
  ${objectId ? cardSqlTable : ""}
301
304
  where ${where.join(" and ") || "true"}
@@ -373,7 +376,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
373
376
  from (select * ${sql
374
377
  ?.filter((el) => el.inline)
375
378
  .map((el) => `,(${el.sql})`)
376
- .join("") || ""} from ${table1} t ${sqlTable})q
379
+ .join("") || ""} from ${viewSql ? `(${viewSql})` : table1} t ${sqlTable})q
377
380
  where ${[loadTable?.query, tokenData?.query, accessQuery, contextQuery]
378
381
  .filter(Boolean)
379
382
  .filter((el) => checkQuery(el))
@@ -1 +1 @@
1
- {"version":3,"file":"code.generator.d.ts","sourceRoot":"","sources":["../../../../../server/routes/util/controllers/code.generator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAazD,wBAA8B,aAAa,CACzC,EACE,EAAqB,EACrB,MAAW,EACX,IAAS,EACT,KAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAC;CAC7B,EACD,KAAK,EAAE,YAAY,kBA8FpB"}
1
+ {"version":3,"file":"code.generator.d.ts","sourceRoot":"","sources":["../../../../../server/routes/util/controllers/code.generator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA0EzD,wBAA8B,aAAa,CACzC,EACE,EAAqB,EACrB,MAAW,EACX,IAAS,EACT,KAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAC;CAC7B,EACD,KAAK,EAAE,YAAY,kBA+GpB"}
@@ -11,6 +11,54 @@ function dayOfTheYear(date) {
11
11
  const day = Math.floor(diff / oneDay);
12
12
  return day;
13
13
  }
14
+ const optionsKeys = [
15
+ "HH",
16
+ "HH12",
17
+ "HH24",
18
+ "MI",
19
+ "SS",
20
+ "YYYY",
21
+ "YY",
22
+ "MONTH",
23
+ "MON",
24
+ "MM",
25
+ "D",
26
+ "DD",
27
+ "DDD",
28
+ // "NUMM",
29
+ // "NUMY",
30
+ ];
31
+ const regexp = new RegExp(`\\b(${optionsKeys.join("|")}|NUM[MY]\\s?\\d?)\\b`, "gi");
32
+ function getOptions(data = {}, pattern = "", numYear = 0, nextNum = 0) {
33
+ const date = new Date();
34
+ const options = {
35
+ HH: date.getHours(), // hours 24h: 14:00 = 14
36
+ HH12: (date.getHours() + 24) % 12 || 12, // hours 12h: 14:00 = 2
37
+ HH24: date.getHours(), // hours 24h: 14:00 = 14
38
+ MI: date.getMinutes(), // minutes
39
+ SS: date.getSeconds(), // seconds
40
+ YYYY: date.getFullYear(), // full year: 2025
41
+ YY: date.getFullYear().toString().substring(2, 4), // last 2 digits of year: 25
42
+ MONTH: date.toLocaleString("en", { month: "long" }).toUpperCase(), // month name: MARCH
43
+ MON: date
44
+ .toLocaleString("en", { month: "long" })
45
+ .substring(0, 3)
46
+ .toUpperCase(), // month name abbrev: MAR
47
+ MM: date.getMonth() + 1, // month number: 1 - january, 12 - december
48
+ D: date.getDay(), // day of the week: 1 - monday, 7 - sunday
49
+ DD: date.getDate(), // day of the month: january 4 = 4
50
+ DDD: dayOfTheYear(date), // day of the year: march 4 = 63
51
+ ...data,
52
+ };
53
+ const template = pattern.match(/NUM[M|Y] ?\d?/g)?.reduce((acc, curr) => {
54
+ const value = handlebarsSync.compile("{{paddingNumber value padding}}")({
55
+ padding: curr.substring(4, curr.length)?.trim?.() || 6,
56
+ value: curr.startsWith("NUMY") ? +numYear : +nextNum,
57
+ });
58
+ return acc.replace(curr.startsWith("{{{") ? `{{{${curr}}}}` : `{{${curr}}}`, value);
59
+ }, pattern) || pattern;
60
+ return { template, options };
61
+ }
14
62
  export default async function codeGenerator({ pg = pgClients.client, params = {}, user = {}, query = {}, }, reply) {
15
63
  const { token, column } = params;
16
64
  const data = query.data?.split?.(";") || [];
@@ -21,6 +69,30 @@ export default async function codeGenerator({ pg = pgClients.client, params = {}
21
69
  return reply.status(401).send("unauthorized");
22
70
  }
23
71
  const tokenData = (await getToken({ token, uid: user?.uid, json: 1 })) || {};
72
+ const currentYear = new Date().getFullYear();
73
+ // unique entity per table, table as key - property_text = pattern as yyyy-mm-dd/numy
74
+ if (pg?.pk?.[token]) {
75
+ const pattern1 = pg
76
+ ? await pg
77
+ .query(`select property_text from admin.properties where property_entity=$1 and property_key=$2`, [`code:${column.replace(/'/g, "''")}`, token])
78
+ .then((el) => el.rows?.[0]?.property_text)
79
+ : null;
80
+ // force pattern keys to upperCase for handlebars compile
81
+ const pattern = (pattern1 || column).replace(regexp, (_, m) => `{{${m.toUpperCase()}}}`);
82
+ const count = pg
83
+ ? await pg
84
+ .query(`select count(*) + 1 as count from ${token}`)
85
+ .then((el) => el.rows?.[0]?.count || 0)
86
+ : 0;
87
+ const numYear = pg
88
+ ? await pg
89
+ .query(`select count(*) + 1 as count from ${token} where date_part('year', created_at)=$1`, [currentYear])
90
+ .then((el) => el.rows?.[0]?.count || 0)
91
+ : 0;
92
+ const { template, options } = getOptions(data, pattern, numYear, count);
93
+ const result = handlebarsSync.compile(template)(options);
94
+ return reply.status(200).send(result);
95
+ }
24
96
  if (!tokenData?.form || !tokenData?.table) {
25
97
  return reply.status(401).send("token not allow");
26
98
  }
@@ -41,35 +113,17 @@ export default async function codeGenerator({ pg = pgClients.client, params = {}
41
113
  if (!pg.pk?.[table]) {
42
114
  return reply.status(404).send("table pk not found");
43
115
  }
44
- const { count = 0 } = await pg
45
- .query(`select count(*) from ${table} where ${columnValue ? `${column}::text = '${columnValue}'` : "true"} limit 1`)
46
- .then((el) => el.rows?.[0] || {});
47
- const { NUMY = 0 } = await pg
48
- .query(`select ${column} as "NUMY" from ${table} where ${column} is not null and date_part('year', cdate) = $1 order by cdate desc limit 1`, [new Date().getFullYear()])
49
- .then((el) => el.rows?.[0] || {});
50
- const date = new Date();
51
- const template = schema[column].template.match(/NUM[M|Y] \d/g).reduce((acc, curr) => acc.replace(curr.startsWith("{{{") ? `{{{${curr}}}}` : `{{${curr}}}`, handlebarsSync.compile("{{paddingNumber value padding}}")({
52
- padding: curr.substring(4, curr.length)?.trim?.(),
53
- value: curr.startsWith("NUMY") ? NUMY : +count + 1,
54
- })), schema[column].template);
55
- const result = handlebarsSync.compile(template)({
56
- HH: date.getHours(), // hours 24h: 14:00 = 14
57
- HH12: (date.getHours() + 24) % 12 || 12, // hours 12h: 14:00 = 2
58
- HH24: date.getHours(), // hours 24h: 14:00 = 14
59
- MI: date.getMinutes(), // minutes
60
- SS: date.getSeconds(), // seconds
61
- YYYY: date.getFullYear(), // full year: 2025
62
- YY: date.getFullYear().toString().substring(2, 4), // last 2 digits of year: 25
63
- MONTH: date.toLocaleString("en", { month: "long" }).toUpperCase(), // month name: MARCH
64
- MON: date
65
- .toLocaleString("en", { month: "long" })
66
- .substring(0, 3)
67
- .toUpperCase(), // month name abbrev: MAR
68
- MM: date.getMonth() + 1, // month number: 1 - january, 12 - december
69
- D: date.getDay(), // day of the week: 1 - monday, 7 - sunday
70
- DD: date.getDate(), // day of the month: january 4 = 4
71
- DDD: dayOfTheYear(date), // day of the year: march 4 = 63
72
- ...data,
73
- });
116
+ const count = pg
117
+ ? await pg
118
+ .query(`select count(*) + 1 as count from ${table} where ${columnValue ? `${column}::text = '${columnValue}'` : "true"} limit 1`)
119
+ .then((el) => el.rows?.[0]?.count || 0)
120
+ : 0;
121
+ const numYear = pg
122
+ ? await pg
123
+ .query(`select ${column} + 1 as count from ${table} where ${column} is not null and date_part('year', cdate) = $1 order by cdate desc limit 1`, [currentYear])
124
+ .then((el) => el.rows?.[0]?.count || 0)
125
+ : 0;
126
+ const { template, options } = getOptions(data, schema[column].template, numYear, count);
127
+ const result = handlebarsSync.compile(template)(options);
74
128
  return reply.status(200).send(result);
75
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.54",
3
+ "version": "2.0.56",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [