@loomcore/api 0.1.123 → 0.1.126

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.
@@ -41,15 +41,21 @@ export const getPostgresInitialSchema = (dbConfig) => {
41
41
  name: '00000000000002_schema-persons',
42
42
  up: async ({ context: pool }) => {
43
43
  const orgColumnDef = isMultiTenant ? '"_orgId" INTEGER,' : '';
44
+ const personsUniqueConstraints = isMultiTenant
45
+ ? `CONSTRAINT "uk_persons_org_external_id" UNIQUE ("_orgId", "external_id"),
46
+ CONSTRAINT "uk_persons_org_ssn" UNIQUE ("_orgId", "ssn")`
47
+ : `CONSTRAINT "uk_persons_external_id" UNIQUE ("external_id"),
48
+ CONSTRAINT "uk_persons_ssn" UNIQUE ("ssn")`;
44
49
  await pool.query(`
45
50
  CREATE TABLE IF NOT EXISTS "persons" (
46
51
  "_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
47
52
  ${orgColumnDef}
48
- "external_id" VARCHAR(255) UNIQUE,
53
+ "external_id" VARCHAR(255),
49
54
  "first_name" VARCHAR(255) NOT NULL,
50
55
  "middle_name" VARCHAR(255),
51
56
  "last_name" VARCHAR(255) NOT NULL,
52
57
  "date_of_birth" DATE,
58
+ "ssn" INTEGER,
53
59
  "is_agent" BOOLEAN NOT NULL DEFAULT FALSE,
54
60
  "is_client" BOOLEAN NOT NULL DEFAULT FALSE,
55
61
  "is_employee" BOOLEAN NOT NULL DEFAULT FALSE,
@@ -59,7 +65,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
59
65
  "_updated" TIMESTAMPTZ NOT NULL,
60
66
  "_updatedBy" INTEGER NOT NULL,
61
67
  "_deleted" TIMESTAMPTZ,
62
- "_deletedBy" INTEGER
68
+ "_deletedBy" INTEGER,
69
+ ${personsUniqueConstraints}
63
70
  )
64
71
  `);
65
72
  },
@@ -43,9 +43,11 @@ export class AuthService extends MultiTenantApiService {
43
43
  if (!passwordsMatch) {
44
44
  throw new BadRequestError('Invalid Credentials');
45
45
  }
46
+ const person = await this.personService.findOne(EmptyUserContext, { filters: { _id: { eq: user.personId } } });
46
47
  const authorizations = await getUserContextAuthorizations(this.database, user);
47
48
  const userContext = {
48
49
  user: user,
50
+ person: person ?? undefined,
49
51
  organization: organization ?? undefined,
50
52
  authorizations: authorizations
51
53
  };
@@ -120,13 +122,21 @@ export class AuthService extends MultiTenantApiService {
120
122
  if (activeRefreshToken) {
121
123
  const systemUserContext = getSystemUserContext();
122
124
  const user = await this.getById(systemUserContext, activeRefreshToken.userId);
125
+ const person = await this.personService.findOne(EmptyUserContext, { filters: { _id: { eq: user?.personId } } });
123
126
  const organization = await this.organizationService.findOne(EmptyUserContext, { filters: { _id: { eq: user?._orgId } } });
124
127
  const authorizations = await getUserContextAuthorizations(this.database, user);
125
- const userContext = {
128
+ let userContext = {
126
129
  user: user,
130
+ person: person ?? undefined,
127
131
  organization: organization ?? undefined,
128
132
  authorizations: authorizations
129
133
  };
134
+ if (user.personId) {
135
+ const person = await this.personService.getById(EmptyUserContext, user.personId);
136
+ if (person) {
137
+ userContext.person = person;
138
+ }
139
+ }
130
140
  tokens = await this.createNewTokens(userContext, activeRefreshToken);
131
141
  }
132
142
  return tokens;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.123",
3
+ "version": "0.1.126",
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": {
@@ -58,7 +58,7 @@
58
58
  "qs": "^6.15.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "@loomcore/common": "^0.0.58",
61
+ "@loomcore/common": "^0.0.63",
62
62
  "@sinclair/typebox": "0.34.33",
63
63
  "cookie-parser": "^1.4.6",
64
64
  "cors": "^2.8.5",