@loomcore/api 0.1.141 → 0.1.143

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.
@@ -83,11 +83,17 @@ export const getPostgresInitialSchema = (dbConfig) => {
83
83
  "_deleted" TIMESTAMPTZ,
84
84
  "_deletedBy" INTEGER,
85
85
  ${personsUniqueConstraints}
86
- )
86
+ );
87
+ CREATE INDEX IF NOT EXISTS "idx_persons_external_id" ON "persons" ("external_id");
88
+ CREATE INDEX IF NOT EXISTS "idx_persons_ssn" ON "persons" ("ssn");
87
89
  `);
88
90
  },
89
91
  down: async ({ context: pool }) => {
90
- await pool.query('DROP TABLE IF EXISTS "persons"');
92
+ await pool.query(`
93
+ DROP INDEX IF EXISTS "idx_persons_external_id";
94
+ DROP INDEX IF EXISTS "idx_persons_ssn";
95
+ DROP TABLE IF EXISTS "persons"
96
+ `);
91
97
  }
92
98
  });
93
99
  if (isAuthEnabled)
@@ -101,28 +107,36 @@ export const getPostgresInitialSchema = (dbConfig) => {
101
107
  uniqueConstraint += `,
102
108
  CONSTRAINT "fk_users_person_id" FOREIGN KEY("person_id") REFERENCES "persons"("_id") ON DELETE CASCADE`;
103
109
  await pool.query(`
104
- CREATE TABLE IF NOT EXISTS "users" (
105
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
106
- ${orgColumnDef}
110
+ CREATE TABLE IF NOT EXISTS "users"(
111
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
112
+ ${orgColumnDef}
107
113
  "external_id" VARCHAR(255) UNIQUE,
108
- "email" VARCHAR(255) NOT NULL,
109
- "display_name" VARCHAR(255),
110
- "password" VARCHAR(255) NOT NULL,
111
- "person_id" INTEGER UNIQUE,
112
- "_lastLoggedIn" TIMESTAMPTZ,
113
- "_lastPasswordChange" TIMESTAMPTZ,
114
- "_created" TIMESTAMPTZ NOT NULL,
115
- "_createdBy" INTEGER NOT NULL,
116
- "_updated" TIMESTAMPTZ NOT NULL,
117
- "_updatedBy" INTEGER NOT NULL,
118
- "_deleted" TIMESTAMPTZ,
119
- "_deletedBy" INTEGER,
120
- ${uniqueConstraint}
121
- )
122
- `);
114
+ "email" VARCHAR(255) NOT NULL,
115
+ "display_name" VARCHAR(255),
116
+ "password" VARCHAR(255) NOT NULL,
117
+ "person_id" INTEGER UNIQUE,
118
+ "_lastLoggedIn" TIMESTAMPTZ,
119
+ "_lastPasswordChange" TIMESTAMPTZ,
120
+ "_created" TIMESTAMPTZ NOT NULL,
121
+ "_createdBy" INTEGER NOT NULL,
122
+ "_updated" TIMESTAMPTZ NOT NULL,
123
+ "_updatedBy" INTEGER NOT NULL,
124
+ "_deleted" TIMESTAMPTZ,
125
+ "_deletedBy" INTEGER,
126
+ ${uniqueConstraint}
127
+ );
128
+ CREATE INDEX IF NOT EXISTS "idx_users_external_id" ON "users"("external_id");
129
+ CREATE INDEX IF NOT EXISTS "idx_users_email" ON "users"("email");
130
+ CREATE INDEX IF NOT EXISTS "idx_users_person_id" ON "users"("person_id");
131
+ `);
123
132
  },
124
133
  down: async ({ context: pool }) => {
125
- await pool.query('DROP TABLE IF EXISTS "users"');
134
+ await pool.query(`
135
+ DROP INDEX IF EXISTS "idx_users_external_id";
136
+ DROP INDEX IF EXISTS "idx_users_email";
137
+ DROP INDEX IF EXISTS "idx_users_person_id";
138
+ DROP TABLE IF EXISTS "users"
139
+ `);
126
140
  }
127
141
  });
128
142
  if (isAuthEnabled)
@@ -131,18 +145,18 @@ export const getPostgresInitialSchema = (dbConfig) => {
131
145
  up: async ({ context: pool }) => {
132
146
  const orgColumnDef = isMultiTenant ? '"_orgId" INTEGER,' : '';
133
147
  await pool.query(`
134
- CREATE TABLE IF NOT EXISTS "refresh_tokens" (
135
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
136
- ${orgColumnDef}
148
+ CREATE TABLE IF NOT EXISTS "refresh_tokens"(
149
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
150
+ ${orgColumnDef}
137
151
  "token" VARCHAR(255) NOT NULL,
138
- "device_id" VARCHAR(255) NOT NULL,
139
- "user_id" INTEGER NOT NULL,
140
- "expires_on" BIGINT NOT NULL,
141
- "created" TIMESTAMPTZ NOT NULL,
142
- "created_by" INTEGER NOT NULL,
143
- CONSTRAINT "fk_refresh_tokens_user" FOREIGN KEY ("user_id") REFERENCES "users"("_id") ON DELETE CASCADE
144
- )
145
- `);
152
+ "device_id" VARCHAR(255) NOT NULL,
153
+ "user_id" INTEGER NOT NULL,
154
+ "expires_on" BIGINT NOT NULL,
155
+ "created" TIMESTAMPTZ NOT NULL,
156
+ "created_by" INTEGER NOT NULL,
157
+ CONSTRAINT "fk_refresh_tokens_user" FOREIGN KEY("user_id") REFERENCES "users"("_id") ON DELETE CASCADE
158
+ )
159
+ `);
146
160
  },
147
161
  down: async ({ context: pool }) => {
148
162
  await pool.query('DROP TABLE IF EXISTS "refresh_tokens"');
@@ -157,21 +171,21 @@ export const getPostgresInitialSchema = (dbConfig) => {
157
171
  ? 'CONSTRAINT "uk_passwordResetTokens_email" UNIQUE ("_orgId", "email")'
158
172
  : 'CONSTRAINT "uk_passwordResetTokens_email" UNIQUE ("email")';
159
173
  await pool.query(`
160
- CREATE TABLE IF NOT EXISTS "password_reset_tokens" (
161
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
162
- ${orgColumnDef}
174
+ CREATE TABLE IF NOT EXISTS "password_reset_tokens"(
175
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
176
+ ${orgColumnDef}
163
177
  "email" VARCHAR(255) NOT NULL,
164
- "token" VARCHAR(255) NOT NULL,
165
- "expires_on" BIGINT NOT NULL,
166
- "_created" TIMESTAMPTZ NOT NULL,
167
- "_createdBy" INTEGER NOT NULL,
168
- "_updated" TIMESTAMPTZ NOT NULL,
169
- "_updatedBy" INTEGER NOT NULL,
170
- "_deleted" TIMESTAMPTZ,
171
- "_deletedBy" INTEGER,
172
- ${uniqueConstraint}
173
- )
174
- `);
178
+ "token" VARCHAR(255) NOT NULL,
179
+ "expires_on" BIGINT NOT NULL,
180
+ "_created" TIMESTAMPTZ NOT NULL,
181
+ "_createdBy" INTEGER NOT NULL,
182
+ "_updated" TIMESTAMPTZ NOT NULL,
183
+ "_updatedBy" INTEGER NOT NULL,
184
+ "_deleted" TIMESTAMPTZ,
185
+ "_deletedBy" INTEGER,
186
+ ${uniqueConstraint}
187
+ )
188
+ `);
175
189
  },
176
190
  down: async ({ context: pool }) => {
177
191
  await pool.query('DROP TABLE IF EXISTS "password_reset_tokens"');
@@ -186,14 +200,14 @@ export const getPostgresInitialSchema = (dbConfig) => {
186
200
  ? 'CONSTRAINT "uk_roles_name" UNIQUE ("_orgId", "name")'
187
201
  : 'CONSTRAINT "uk_roles_name" UNIQUE ("name")';
188
202
  await pool.query(`
189
- CREATE TABLE IF NOT EXISTS "roles" (
190
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
191
- ${orgColumnDef}
203
+ CREATE TABLE IF NOT EXISTS "roles"(
204
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
205
+ ${orgColumnDef}
192
206
  "name" VARCHAR(255) NOT NULL,
193
- "description" TEXT,
194
- ${uniqueConstraint}
195
- )
196
- `);
207
+ "description" TEXT,
208
+ ${uniqueConstraint}
209
+ )
210
+ `);
197
211
  },
198
212
  down: async ({ context: pool }) => {
199
213
  await pool.query('DROP TABLE IF EXISTS "roles"');
@@ -208,22 +222,22 @@ export const getPostgresInitialSchema = (dbConfig) => {
208
222
  ? 'CONSTRAINT "uk_user_roles" UNIQUE ("_orgId", "user_id", "role_id")'
209
223
  : 'CONSTRAINT "uk_user_roles" UNIQUE ("user_id", "role_id")';
210
224
  await pool.query(`
211
- CREATE TABLE IF NOT EXISTS "user_roles" (
212
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
213
- ${orgColumnDef}
225
+ CREATE TABLE IF NOT EXISTS "user_roles"(
226
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
227
+ ${orgColumnDef}
214
228
  "user_id" INTEGER NOT NULL,
215
- "role_id" INTEGER NOT NULL,
216
- "_created" TIMESTAMPTZ NOT NULL,
217
- "_createdBy" INTEGER NOT NULL,
218
- "_updated" TIMESTAMPTZ NOT NULL,
219
- "_updatedBy" INTEGER NOT NULL,
220
- "_deleted" TIMESTAMPTZ,
221
- "_deletedBy" INTEGER,
222
- CONSTRAINT "fk_user_roles_user" FOREIGN KEY ("user_id") REFERENCES "users"("_id") ON DELETE CASCADE,
223
- CONSTRAINT "fk_user_roles_role" FOREIGN KEY ("role_id") REFERENCES "roles"("_id") ON DELETE CASCADE,
224
- ${uniqueConstraint}
225
- )
226
- `);
229
+ "role_id" INTEGER NOT NULL,
230
+ "_created" TIMESTAMPTZ NOT NULL,
231
+ "_createdBy" INTEGER NOT NULL,
232
+ "_updated" TIMESTAMPTZ NOT NULL,
233
+ "_updatedBy" INTEGER NOT NULL,
234
+ "_deleted" TIMESTAMPTZ,
235
+ "_deletedBy" INTEGER,
236
+ CONSTRAINT "fk_user_roles_user" FOREIGN KEY("user_id") REFERENCES "users"("_id") ON DELETE CASCADE,
237
+ CONSTRAINT "fk_user_roles_role" FOREIGN KEY("role_id") REFERENCES "roles"("_id") ON DELETE CASCADE,
238
+ ${uniqueConstraint}
239
+ )
240
+ `);
227
241
  },
228
242
  down: async ({ context: pool }) => {
229
243
  await pool.query('DROP TABLE IF EXISTS "user_roles"');
@@ -238,14 +252,14 @@ export const getPostgresInitialSchema = (dbConfig) => {
238
252
  ? 'CONSTRAINT "uk_features" UNIQUE ("_orgId", "name")'
239
253
  : 'CONSTRAINT "uk_features" UNIQUE ("name")';
240
254
  await pool.query(`
241
- CREATE TABLE IF NOT EXISTS "features" (
242
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
243
- ${orgColumnDef}
255
+ CREATE TABLE IF NOT EXISTS "features"(
256
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
257
+ ${orgColumnDef}
244
258
  "name" VARCHAR(255) NOT NULL,
245
- "description" TEXT,
246
- ${uniqueConstraint}
247
- )
248
- `);
259
+ "description" TEXT,
260
+ ${uniqueConstraint}
261
+ )
262
+ `);
249
263
  },
250
264
  down: async ({ context: pool }) => {
251
265
  await pool.query('DROP TABLE IF EXISTS "features"');
@@ -260,25 +274,25 @@ export const getPostgresInitialSchema = (dbConfig) => {
260
274
  ? 'CONSTRAINT "uk_authorizations" UNIQUE ("_orgId", "role_id", "feature_id")'
261
275
  : 'CONSTRAINT "uk_authorizations" UNIQUE ("role_id", "feature_id")';
262
276
  await pool.query(`
263
- CREATE TABLE IF NOT EXISTS "authorizations" (
264
- "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
265
- ${orgColumnDef}
277
+ CREATE TABLE IF NOT EXISTS "authorizations"(
278
+ "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
279
+ ${orgColumnDef}
266
280
  "role_id" INTEGER NOT NULL,
267
- "feature_id" INTEGER NOT NULL,
268
- "start_date" TIMESTAMPTZ,
269
- "end_date" TIMESTAMPTZ,
270
- "config" JSONB,
271
- "_created" TIMESTAMPTZ NOT NULL,
272
- "_createdBy" INTEGER NOT NULL,
273
- "_updated" TIMESTAMPTZ NOT NULL,
274
- "_updatedBy" INTEGER NOT NULL,
275
- "_deleted" TIMESTAMPTZ,
276
- "_deletedBy" INTEGER,
277
- CONSTRAINT "fk_authorizations_role" FOREIGN KEY ("role_id") REFERENCES "roles"("_id") ON DELETE CASCADE,
278
- CONSTRAINT "fk_authorizations_feature" FOREIGN KEY ("feature_id") REFERENCES "features"("_id") ON DELETE CASCADE,
279
- ${uniqueConstraint}
280
- )
281
- `);
281
+ "feature_id" INTEGER NOT NULL,
282
+ "start_date" TIMESTAMPTZ,
283
+ "end_date" TIMESTAMPTZ,
284
+ "config" JSONB,
285
+ "_created" TIMESTAMPTZ NOT NULL,
286
+ "_createdBy" INTEGER NOT NULL,
287
+ "_updated" TIMESTAMPTZ NOT NULL,
288
+ "_updatedBy" INTEGER NOT NULL,
289
+ "_deleted" TIMESTAMPTZ,
290
+ "_deletedBy" INTEGER,
291
+ CONSTRAINT "fk_authorizations_role" FOREIGN KEY("role_id") REFERENCES "roles"("_id") ON DELETE CASCADE,
292
+ CONSTRAINT "fk_authorizations_feature" FOREIGN KEY("feature_id") REFERENCES "features"("_id") ON DELETE CASCADE,
293
+ ${uniqueConstraint}
294
+ )
295
+ `);
282
296
  },
283
297
  down: async ({ context: pool }) => {
284
298
  await pool.query('DROP TABLE IF EXISTS "authorizations"');
@@ -289,10 +303,10 @@ export const getPostgresInitialSchema = (dbConfig) => {
289
303
  name: '00000000000011_data-meta-org',
290
304
  up: async ({ context: pool }) => {
291
305
  const result = await pool.query(`
292
- INSERT INTO "organizations" ("name", "code", "status", "is_meta_org", "_created", "_createdBy", "_updated", "_updatedBy")
293
- VALUES ($1, $2, 1, true, NOW(), 0, NOW(), 0)
306
+ INSERT INTO "organizations"("name", "code", "status", "is_meta_org", "_created", "_createdBy", "_updated", "_updatedBy")
307
+ VALUES($1, $2, 1, true, NOW(), 0, NOW(), 0)
294
308
  RETURNING "_id", "name", "code", "status", "is_meta_org", "_created", "_createdBy", "_updated", "_updatedBy"
295
- `, [dbConfig.multiTenant?.metaOrgName, dbConfig.multiTenant?.metaOrgCode]);
309
+ `, [dbConfig.multiTenant?.metaOrgName, dbConfig.multiTenant?.metaOrgCode]);
296
310
  if (result.rowCount === 0) {
297
311
  throw new Error('Failed to create meta organization');
298
312
  }
@@ -322,20 +336,20 @@ export const getPostgresInitialSchema = (dbConfig) => {
322
336
  const client = await pool.connect();
323
337
  try {
324
338
  const personResult = isMultiTenant && orgId
325
- ? await client.query(`INSERT INTO "persons" ("_orgId", "first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy", "_updated", "_updatedBy")
326
- VALUES ($1, 'Admin', 'User', false, false, false, NOW(), 0, NOW(), 0)
339
+ ? await client.query(`INSERT INTO "persons"("_orgId", "first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy", "_updated", "_updatedBy")
340
+ VALUES($1, 'Admin', 'User', false, false, false, NOW(), 0, NOW(), 0)
327
341
  RETURNING "_id"`, [orgId])
328
- : await client.query(`INSERT INTO "persons" ("first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy", "_updated", "_updatedBy")
329
- VALUES ('Admin', 'User', false, false, false, NOW(), 0, NOW(), 0)
342
+ : await client.query(`INSERT INTO "persons"("first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy", "_updated", "_updatedBy")
343
+ VALUES('Admin', 'User', false, false, false, NOW(), 0, NOW(), 0)
330
344
  RETURNING "_id"`);
331
345
  const personId = personResult.rows[0]._id;
332
346
  if (isMultiTenant && orgId) {
333
- await client.query(`INSERT INTO "users" ("_orgId", "email", "display_name", "password", "person_id", "_created", "_createdBy", "_updated", "_updatedBy")
334
- VALUES ($1, $2, 'Admin User', $3, $4, NOW(), 0, NOW(), 0)`, [orgId, email, hashedPassword, personId]);
347
+ await client.query(`INSERT INTO "users"("_orgId", "email", "display_name", "password", "person_id", "_created", "_createdBy", "_updated", "_updatedBy")
348
+ VALUES($1, $2, 'Admin User', $3, $4, NOW(), 0, NOW(), 0)`, [orgId, email, hashedPassword, personId]);
335
349
  }
336
350
  else {
337
- await client.query(`INSERT INTO "users" ("email", "display_name", "password", "person_id", "_created", "_createdBy", "_updated", "_updatedBy")
338
- VALUES ($1, 'Admin User', $2, $3, NOW(), 0, NOW(), 0)`, [email, hashedPassword, personId]);
351
+ await client.query(`INSERT INTO "users"("email", "display_name", "password", "person_id", "_created", "_createdBy", "_updated", "_updatedBy")
352
+ VALUES($1, 'Admin User', $2, $3, NOW(), 0, NOW(), 0)`, [email, hashedPassword, personId]);
339
353
  }
340
354
  }
341
355
  finally {
@@ -372,61 +386,61 @@ export const getPostgresInitialSchema = (dbConfig) => {
372
386
  try {
373
387
  const roleResult = isMultiTenant
374
388
  ? await client.query(`
375
- INSERT INTO "roles" ("_orgId", "name")
376
- VALUES ($1, 'admin')
389
+ INSERT INTO "roles"("_orgId", "name")
390
+ VALUES($1, 'admin')
377
391
  RETURNING "_id"
378
- `, [metaOrg._id])
392
+ `, [metaOrg._id])
379
393
  : await client.query(`
380
- INSERT INTO "roles" ("name")
381
- VALUES ('admin')
394
+ INSERT INTO "roles"("name")
395
+ VALUES('admin')
382
396
  RETURNING "_id"
383
- `);
397
+ `);
384
398
  if (roleResult.rowCount === 0) {
385
399
  throw new Error('Failed to create admin role');
386
400
  }
387
401
  const roleId = roleResult.rows[0]._id;
388
402
  const userRoleResult = isMultiTenant
389
403
  ? await client.query(`
390
- INSERT INTO "user_roles" ("_orgId", "user_id", "role_id", "_created", "_createdBy", "_updated", "_updatedBy")
391
- VALUES ($1, $2, $3, NOW(), 0, NOW(), 0)
392
- `, [metaOrg._id, adminUserId, roleId])
404
+ INSERT INTO "user_roles"("_orgId", "user_id", "role_id", "_created", "_createdBy", "_updated", "_updatedBy")
405
+ VALUES($1, $2, $3, NOW(), 0, NOW(), 0)
406
+ `, [metaOrg._id, adminUserId, roleId])
393
407
  : await client.query(`
394
- INSERT INTO "user_roles" ("user_id", "role_id", "_created", "_createdBy", "_updated", "_updatedBy")
395
- VALUES ($1, $2, NOW(), 0, NOW(), 0)
396
- `, [adminUserId, roleId]);
408
+ INSERT INTO "user_roles"("user_id", "role_id", "_created", "_createdBy", "_updated", "_updatedBy")
409
+ VALUES($1, $2, NOW(), 0, NOW(), 0)
410
+ `, [adminUserId, roleId]);
397
411
  if (userRoleResult.rowCount === 0) {
398
412
  throw new Error('Failed to create user role');
399
413
  }
400
414
  const featureResult = isMultiTenant
401
415
  ? await client.query(`
402
- INSERT INTO "features" ("_orgId", "name")
403
- VALUES ($1, 'admin')
416
+ INSERT INTO "features"("_orgId", "name")
417
+ VALUES($1, 'admin')
404
418
  RETURNING "_id"
405
- `, [metaOrg._id])
419
+ `, [metaOrg._id])
406
420
  : await client.query(`
407
- INSERT INTO "features" ("name")
408
- VALUES ('admin')
421
+ INSERT INTO "features"("name")
422
+ VALUES('admin')
409
423
  RETURNING "_id"
410
- `);
424
+ `);
411
425
  if (featureResult.rowCount === 0) {
412
426
  throw new Error('Failed to create admin feature');
413
427
  }
414
428
  const featureId = featureResult.rows[0]._id;
415
429
  const authorizationResult = isMultiTenant
416
430
  ? await client.query(`
417
- INSERT INTO "authorizations" (
418
- "_orgId", "role_id", "feature_id",
419
- "_created", "_createdBy", "_updated", "_updatedBy"
420
- )
421
- VALUES ($1, $2, $3, NOW(), 0, NOW(), 0)
422
- `, [metaOrg._id, roleId, featureId])
431
+ INSERT INTO "authorizations"(
432
+ "_orgId", "role_id", "feature_id",
433
+ "_created", "_createdBy", "_updated", "_updatedBy"
434
+ )
435
+ VALUES($1, $2, $3, NOW(), 0, NOW(), 0)
436
+ `, [metaOrg._id, roleId, featureId])
423
437
  : await client.query(`
424
- INSERT INTO "authorizations" (
425
- "role_id", "feature_id",
426
- "_created", "_createdBy", "_updated", "_updatedBy"
427
- )
428
- VALUES ($1, $2, NOW(), 0, NOW(), 0)
429
- `, [roleId, featureId]);
438
+ INSERT INTO "authorizations"(
439
+ "role_id", "feature_id",
440
+ "_created", "_createdBy", "_updated", "_updatedBy"
441
+ )
442
+ VALUES($1, $2, NOW(), 0, NOW(), 0)
443
+ `, [roleId, featureId]);
430
444
  if (authorizationResult.rowCount === 0) {
431
445
  throw new Error('Failed to create admin authorization');
432
446
  }
@@ -455,59 +469,59 @@ export const getPostgresInitialSchema = (dbConfig) => {
455
469
  await client.query(`
456
470
  DELETE FROM "authorizations"
457
471
  WHERE "_orgId" = $1
458
- AND "feature_id" IN (
459
- SELECT "_id" FROM "features"
472
+ AND "feature_id" IN(
473
+ SELECT "_id" FROM "features"
460
474
  WHERE "_orgId" = $1 AND "name" = 'admin'
461
- )
462
- AND "role_id" IN (
463
- SELECT "_id" FROM "roles"
475
+ )
476
+ AND "role_id" IN(
477
+ SELECT "_id" FROM "roles"
464
478
  WHERE "_orgId" = $1 AND "name" = 'admin'
465
- )
466
- `, [metaOrg._id]);
479
+ )
480
+ `, [metaOrg._id]);
467
481
  await client.query(`
468
482
  DELETE FROM "features"
469
483
  WHERE "_orgId" = $1 AND "name" = 'admin'
470
- `, [metaOrg._id]);
484
+ `, [metaOrg._id]);
471
485
  await client.query(`
472
486
  DELETE FROM "user_roles"
473
487
  WHERE "_orgId" = $1
474
- AND "role_id" IN (
475
- SELECT "_id" FROM "roles"
488
+ AND "role_id" IN(
489
+ SELECT "_id" FROM "roles"
476
490
  WHERE "_orgId" = $1 AND "name" = 'admin'
477
- )
478
- `, [metaOrg._id]);
491
+ )
492
+ `, [metaOrg._id]);
479
493
  await client.query(`
480
494
  DELETE FROM "roles"
481
495
  WHERE "_orgId" = $1 AND "name" = 'admin'
482
- `, [metaOrg._id]);
496
+ `, [metaOrg._id]);
483
497
  }
484
498
  else {
485
499
  await client.query(`
486
500
  DELETE FROM "authorizations"
487
- WHERE "feature_id" IN (
488
- SELECT "_id" FROM "features"
501
+ WHERE "feature_id" IN(
502
+ SELECT "_id" FROM "features"
489
503
  WHERE "name" = 'admin'
490
- )
491
- AND "role_id" IN (
492
- SELECT "_id" FROM "roles"
504
+ )
505
+ AND "role_id" IN(
506
+ SELECT "_id" FROM "roles"
493
507
  WHERE "name" = 'admin'
494
- )
495
- `);
508
+ )
509
+ `);
496
510
  await client.query(`
497
511
  DELETE FROM "features"
498
512
  WHERE "name" = 'admin'
499
- `);
513
+ `);
500
514
  await client.query(`
501
515
  DELETE FROM "user_roles"
502
- WHERE "role_id" IN (
503
- SELECT "_id" FROM "roles"
516
+ WHERE "role_id" IN(
517
+ SELECT "_id" FROM "roles"
504
518
  WHERE "name" = 'admin'
505
- )
506
- `);
519
+ )
520
+ `);
507
521
  await client.query(`
508
522
  DELETE FROM "roles"
509
523
  WHERE "name" = 'admin'
510
- `);
524
+ `);
511
525
  }
512
526
  await client.query('COMMIT');
513
527
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.141",
3
+ "version": "0.1.143",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {