@saltcorn/reservable 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/table-provider.js +13 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/reservable",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Reservable resources",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/table-provider.js CHANGED
@@ -164,7 +164,7 @@ module.exports = {
164
164
  }
165
165
  return [
166
166
  {
167
- name: "reserve_ident",
167
+ name: "id",
168
168
  type: "String",
169
169
  primary_key: true,
170
170
  is_unique: true,
@@ -196,7 +196,7 @@ module.exports = {
196
196
  name: "service",
197
197
  label: "Service",
198
198
  type: "String",
199
- attributes: { options: cfg.services.map((s) => s.title) },
199
+ attributes: { options: cfg.services.map((s) => s.title).join(",") },
200
200
  },
201
201
  {
202
202
  name: "service_duration",
@@ -220,14 +220,19 @@ module.exports = {
220
220
  get_table: (cfg) => {
221
221
  return {
222
222
  disableFiltering: true,
223
- getRows: async (where, opts) => {
223
+ getRows: async (where0, opts) => {
224
+ const where = { ...where0 };
224
225
  const table = Table.findOne({ name: cfg.table_name });
225
- const date = !where?.start_day
226
+ let date = !where?.start_day
226
227
  ? new Date()
227
228
  : where?.start_day.constructor.name === "PlainDate"
228
229
  ? where.start_day.toDate()
229
230
  : new Date(where?.start_day);
230
-
231
+ if (typeof where?.id === "string") {
232
+ const service = where?.id.split("//")[1];
233
+ if (service) where.service = service;
234
+ date = new Date(where?.id.split("//")[0]);
235
+ }
231
236
  const services = where?.service
232
237
  ? cfg.services.filter((s) => s.title === where.service)
233
238
  : cfg.services;
@@ -280,7 +285,7 @@ module.exports = {
280
285
  .filter((a) => a.available)
281
286
  .map(({ date }) => {
282
287
  return {
283
- reserve_ident: `${date.toISOString()}//${service.title}`,
288
+ id: `${date.toISOString()}//${service.title}`,
284
289
  service: service.title,
285
290
  service_duration: service.duration,
286
291
  start_day: new PlainDate(date),
@@ -291,7 +296,8 @@ module.exports = {
291
296
  })
292
297
  )
293
298
  .flat();
294
- return rows;
299
+ if (where?.id) return rows.filter((r) => r.id === where.id);
300
+ else return rows;
295
301
  },
296
302
  };
297
303
  },