@loomcore/api 0.1.34 → 0.1.35

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.
@@ -20,8 +20,8 @@ export class CreateUserRolesTableMigration {
20
20
  CREATE TABLE "user_roles" (
21
21
  "_id" VARCHAR(255) PRIMARY KEY,
22
22
  "_orgId" VARCHAR(255),
23
- "_userId" VARCHAR(255) NOT NULL,
24
- "_roleId" VARCHAR(255) NOT NULL,
23
+ "userId" VARCHAR(255) NOT NULL,
24
+ "roleId" VARCHAR(255) NOT NULL,
25
25
  "_created" TIMESTAMP NOT NULL,
26
26
  "_createdBy" VARCHAR(255) NOT NULL,
27
27
  "_updated" TIMESTAMP NOT NULL,
@@ -29,9 +29,9 @@ export class CreateUserRolesTableMigration {
29
29
  "_deleted" TIMESTAMP,
30
30
  "_deletedBy" VARCHAR(255),
31
31
  ${fkConstraint}
32
- CONSTRAINT "fk_user_roles_user" FOREIGN KEY ("_userId") REFERENCES "users"("_id") ON DELETE CASCADE,
33
- CONSTRAINT "fk_user_roles_role" FOREIGN KEY ("_roleId") REFERENCES "roles"("_id") ON DELETE CASCADE,
34
- CONSTRAINT "uk_user_roles" UNIQUE ("_orgId", "_userId", "_roleId")
32
+ CONSTRAINT "fk_user_roles_user" FOREIGN KEY ("userId") REFERENCES "users"("_id") ON DELETE CASCADE,
33
+ CONSTRAINT "fk_user_roles_role" FOREIGN KEY ("roleId") REFERENCES "roles"("_id") ON DELETE CASCADE,
34
+ CONSTRAINT "uk_user_roles" UNIQUE ("_orgId", "userId", "roleId")
35
35
  )
36
36
  `);
37
37
  }
@@ -20,8 +20,8 @@ export class CreateAuthorizationsTableMigration {
20
20
  CREATE TABLE "authorizations" (
21
21
  "_id" VARCHAR(255) PRIMARY KEY,
22
22
  "_orgId" VARCHAR(255),
23
- "_roleId" VARCHAR(255) NOT NULL,
24
- "_featureId" VARCHAR(255) NOT NULL,
23
+ "roleId" VARCHAR(255) NOT NULL,
24
+ "featureId" VARCHAR(255) NOT NULL,
25
25
  "startDate" TIMESTAMP,
26
26
  "endDate" TIMESTAMP,
27
27
  "config" JSONB,
@@ -31,9 +31,9 @@ export class CreateAuthorizationsTableMigration {
31
31
  "_updatedBy" VARCHAR(255) NOT NULL,
32
32
  "_deleted" TIMESTAMP,
33
33
  "_deletedBy" VARCHAR(255),
34
- CONSTRAINT "fk_authorizations_role" FOREIGN KEY ("_roleId") REFERENCES "roles"("_id") ON DELETE CASCADE,
35
- CONSTRAINT "fk_authorizations_feature" FOREIGN KEY ("_featureId") REFERENCES "features"("_id") ON DELETE CASCADE,
36
- CONSTRAINT "uk_authorizations" UNIQUE ("_orgId", "_roleId", "_featureId")${fkConstraint}
34
+ CONSTRAINT "fk_authorizations_role" FOREIGN KEY ("roleId") REFERENCES "roles"("_id") ON DELETE CASCADE,
35
+ CONSTRAINT "fk_authorizations_feature" FOREIGN KEY ("featureId") REFERENCES "features"("_id") ON DELETE CASCADE,
36
+ CONSTRAINT "uk_authorizations" UNIQUE ("_orgId", "roleId", "featureId")${fkConstraint}
37
37
  )
38
38
  `);
39
39
  }
@@ -37,7 +37,7 @@ export class CreateAdminAuthorizationMigration {
37
37
  }
38
38
  const userRoleId = randomUUID().toString();
39
39
  const userRoleResult = await this.client.query(`
40
- INSERT INTO "user_roles" ("_id", "_orgId", "_userId", "_roleId", "_created", "_createdBy", "_updated", "_updatedBy")
40
+ INSERT INTO "user_roles" ("_id", "_orgId", "userId", "roleId", "_created", "_createdBy", "_updated", "_updatedBy")
41
41
  VALUES ($1, $2, $3, $4, NOW(), 'system', NOW(), 'system')
42
42
  `, [userRoleId, metaOrg?._id, adminUser?._id, roleId]);
43
43
  if (userRoleResult.rowCount === 0) {
@@ -56,7 +56,7 @@ export class CreateAdminAuthorizationMigration {
56
56
  const authorizationId = randomUUID().toString();
57
57
  const authorizationResult = await this.client.query(`
58
58
  INSERT INTO "authorizations" (
59
- "_id", "_orgId", "_roleId", "_featureId",
59
+ "_id", "_orgId", "roleId", "featureId",
60
60
  "_created", "_createdBy", "_updated", "_updatedBy"
61
61
  )
62
62
  VALUES ($1, $2, $3, $4, NOW(), 'system', NOW(), 'system')
@@ -74,7 +74,7 @@ export class PostgresDatabase {
74
74
  const placeholders = userIds.map((_, i) => `$${i + 1}`).join(', ');
75
75
  let query = `
76
76
  SELECT DISTINCT
77
- ur."_userId" as "userId",
77
+ ur."userId" as "userId",
78
78
  r."name" as "role",
79
79
  f."name" as "feature",
80
80
  a."config",
@@ -85,10 +85,10 @@ export class PostgresDatabase {
85
85
  a."_updated",
86
86
  a."_updatedBy"
87
87
  FROM "user_roles" ur
88
- INNER JOIN "roles" r ON ur."_roleId" = r."_id"
89
- INNER JOIN "authorizations" a ON r."_id" = a."_roleId"
90
- INNER JOIN "features" f ON a."_featureId" = f."_id"
91
- WHERE ur."_userId" IN (${placeholders})
88
+ INNER JOIN "roles" r ON ur."roleId" = r."_id"
89
+ INNER JOIN "authorizations" a ON r."_id" = a."roleId"
90
+ INNER JOIN "features" f ON a."featureId" = f."_id"
91
+ WHERE ur."userId" IN (${placeholders})
92
92
  AND ur."_deleted" IS NULL
93
93
  AND a."_deleted" IS NULL
94
94
  AND (a."startDate" IS NULL OR a."startDate" <= $${userIds.length + 1})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
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": {