@loomcore/api 0.1.77 → 0.1.79
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.
- package/README.md +1 -1
- package/dist/__tests__/common-test.utils.js +5 -3
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +25 -0
- package/dist/__tests__/postgres.test-database.js +2 -2
- package/dist/__tests__/test-objects.d.ts +6 -1
- package/dist/__tests__/test-objects.js +50 -4
- package/dist/controllers/auth.controller.d.ts +2 -0
- package/dist/controllers/auth.controller.js +9 -4
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +23 -5
- package/dist/databases/operations/__tests__/models/{agent.model.d.ts → test-agent.model.d.ts} +7 -7
- package/dist/databases/operations/__tests__/models/test-agent.model.js +8 -0
- package/dist/databases/operations/__tests__/models/{client-report.model.d.ts → test-client-report.model.d.ts} +21 -16
- package/dist/databases/operations/__tests__/models/test-client-report.model.js +11 -0
- package/dist/databases/operations/__tests__/models/test-district.model.d.ts +12 -0
- package/dist/databases/operations/__tests__/models/{district.model.js → test-district.model.js} +2 -2
- package/dist/databases/operations/__tests__/models/{email-address.model.d.ts → test-email-address.model.d.ts} +3 -3
- package/dist/databases/operations/__tests__/models/{email-address.model.js → test-email-address.model.js} +2 -2
- package/dist/databases/operations/__tests__/models/test-person.model.d.ts +28 -0
- package/dist/databases/operations/__tests__/models/test-person.model.js +12 -0
- package/dist/databases/operations/__tests__/models/{phone-number.model.d.ts → test-phone-number.model.d.ts} +3 -3
- package/dist/databases/operations/__tests__/models/{phone-number.model.js → test-phone-number.model.js} +2 -2
- package/dist/databases/operations/__tests__/models/{policy.model.d.ts → test-policy.model.d.ts} +14 -7
- package/dist/databases/operations/__tests__/models/test-policy.model.js +12 -0
- package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +12 -0
- package/dist/databases/operations/__tests__/models/test-premium.model.js +8 -0
- package/dist/databases/operations/__tests__/models/test-school.model.d.ts +12 -0
- package/dist/databases/operations/__tests__/models/{school.model.js → test-school.model.js} +2 -2
- package/dist/databases/operations/__tests__/models/test-state.model.d.ts +8 -0
- package/dist/databases/operations/__tests__/models/test-state.model.js +6 -0
- package/dist/databases/operations/join-many.operation.js +3 -0
- package/dist/databases/operations/join-through-many.operation.js +3 -0
- package/dist/databases/operations/join-through.operation.js +3 -0
- package/dist/databases/operations/join.operation.js +3 -0
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +54 -16
- package/dist/databases/postgres/utils/build-join-clauses.js +282 -272
- package/dist/databases/postgres/utils/build-select-clause.js +19 -34
- package/dist/databases/postgres/utils/transform-join-results.js +198 -194
- package/dist/services/auth.service.d.ts +3 -2
- package/dist/services/auth.service.js +15 -1
- package/dist/services/person.service.d.ts +6 -0
- package/dist/services/person.service.js +7 -0
- package/package.json +3 -3
- package/dist/databases/operations/__tests__/models/agent.model.js +0 -8
- package/dist/databases/operations/__tests__/models/client-report.model.js +0 -11
- package/dist/databases/operations/__tests__/models/district.model.d.ts +0 -12
- package/dist/databases/operations/__tests__/models/person.model.d.ts +0 -28
- package/dist/databases/operations/__tests__/models/person.model.js +0 -12
- package/dist/databases/operations/__tests__/models/policy.model.js +0 -10
- package/dist/databases/operations/__tests__/models/school.model.d.ts +0 -12
- package/dist/databases/operations/__tests__/models/state.model.d.ts +0 -8
- package/dist/databases/operations/__tests__/models/state.model.js +0 -6
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ The test suite supports two modes for PostgreSQL testing:
|
|
|
63
63
|
npm run test:db:stop
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
The container uses port `
|
|
66
|
+
The container uses port `5444` to avoid conflicts with local PostgreSQL instances. Set `USE_REAL_POSTGRES=true` to use the container instead of pg-mem.
|
|
67
67
|
|
|
68
68
|
## Example Usage
|
|
69
69
|
|
|
@@ -17,7 +17,7 @@ import { CategorySpec } from './models/category.model.js';
|
|
|
17
17
|
import { ProductSpec } from './models/product.model.js';
|
|
18
18
|
import { setBaseApiConfig, config } from '../config/index.js';
|
|
19
19
|
import { entityUtils } from '@loomcore/common/utils';
|
|
20
|
-
import { getTestOrgUser } from './test-objects.js';
|
|
20
|
+
import { getTestMetaOrgUserPerson, getTestOrgUser, getTestOrgUserPerson, setTestMetaOrgUserPersonId, setTestOrgUserPersonId } from './test-objects.js';
|
|
21
21
|
import { TestEmailClient } from './test-email-client.js';
|
|
22
22
|
let deviceIdCookie;
|
|
23
23
|
let authService;
|
|
@@ -110,13 +110,15 @@ async function createTestUsers() {
|
|
|
110
110
|
else {
|
|
111
111
|
setTestOrgId(existingTestOrg._id);
|
|
112
112
|
}
|
|
113
|
-
const createdTestOrgUser = await authService.createUser(getTestOrgUserContext(), getTestOrgUser());
|
|
114
|
-
const createdMetaOrgUser = await authService.createUser(getTestMetaOrgUserContext(), getTestMetaOrgUser());
|
|
113
|
+
const createdTestOrgUser = await authService.createUser(getTestOrgUserContext(), getTestOrgUser(), getTestOrgUserPerson());
|
|
114
|
+
const createdMetaOrgUser = await authService.createUser(getTestMetaOrgUserContext(), getTestMetaOrgUser(), getTestMetaOrgUserPerson());
|
|
115
115
|
if (!createdTestOrgUser || !createdMetaOrgUser) {
|
|
116
116
|
throw new Error('Failed to create test user');
|
|
117
117
|
}
|
|
118
118
|
setTestMetaOrgUserId(createdMetaOrgUser._id);
|
|
119
|
+
setTestMetaOrgUserPersonId(createdMetaOrgUser.personId);
|
|
119
120
|
setTestOrgUserId(createdTestOrgUser._id);
|
|
121
|
+
setTestOrgUserPersonId(createdTestOrgUser.personId);
|
|
120
122
|
return { metaOrgUser: createdMetaOrgUser, testOrgUser: createdTestOrgUser };
|
|
121
123
|
}
|
|
122
124
|
catch (error) {
|
|
@@ -222,6 +222,31 @@ export const getPostgresTestSchema = (config) => {
|
|
|
222
222
|
await pool.query('DROP TABLE IF EXISTS "agents_policies"');
|
|
223
223
|
}
|
|
224
224
|
});
|
|
225
|
+
migrations.push({
|
|
226
|
+
name: '00000000000105_9_schema-premiums',
|
|
227
|
+
up: async ({ context: pool }) => {
|
|
228
|
+
const orgColumnDef = isMultiTenant ? '"_orgId" INTEGER,' : '';
|
|
229
|
+
await pool.query(`
|
|
230
|
+
CREATE TABLE IF NOT EXISTS "premiums" (
|
|
231
|
+
"_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
232
|
+
${orgColumnDef}
|
|
233
|
+
"policy_id" INTEGER NOT NULL,
|
|
234
|
+
"amount" NUMERIC NOT NULL,
|
|
235
|
+
"date" DATE NOT NULL,
|
|
236
|
+
"_created" TIMESTAMPTZ NOT NULL,
|
|
237
|
+
"_createdBy" INTEGER NOT NULL,
|
|
238
|
+
"_updated" TIMESTAMPTZ NOT NULL,
|
|
239
|
+
"_updatedBy" INTEGER NOT NULL,
|
|
240
|
+
"_deleted" TIMESTAMPTZ,
|
|
241
|
+
"_deletedBy" INTEGER,
|
|
242
|
+
CONSTRAINT fk_premiums_policy_id FOREIGN KEY ("policy_id") REFERENCES policies("_id") ON DELETE CASCADE
|
|
243
|
+
)
|
|
244
|
+
`);
|
|
245
|
+
},
|
|
246
|
+
down: async ({ context: pool }) => {
|
|
247
|
+
await pool.query('DROP TABLE IF EXISTS "premiums"');
|
|
248
|
+
}
|
|
249
|
+
});
|
|
225
250
|
migrations.push({
|
|
226
251
|
name: '00000000000106_schema-email-addresses',
|
|
227
252
|
up: async ({ context: pool }) => {
|
|
@@ -25,7 +25,7 @@ export class TestPostgresDatabase {
|
|
|
25
25
|
let postgresClient;
|
|
26
26
|
let pool;
|
|
27
27
|
if (USE_REAL_POSTGRES) {
|
|
28
|
-
const connectionString = `postgresql://test-user:test-password@localhost:
|
|
28
|
+
const connectionString = `postgresql://test-user:test-password@localhost:5444/test-db`;
|
|
29
29
|
postgresClient = new Client({
|
|
30
30
|
connectionString,
|
|
31
31
|
connectionTimeoutMillis: 5000,
|
|
@@ -43,7 +43,7 @@ export class TestPostgresDatabase {
|
|
|
43
43
|
`3. Try: docker ps (to verify Docker access)\n` +
|
|
44
44
|
`Original error: ${errorMessage}`);
|
|
45
45
|
}
|
|
46
|
-
throw new Error(`Failed to connect to PostgreSQL test container at localhost:
|
|
46
|
+
throw new Error(`Failed to connect to PostgreSQL test container at localhost:5444.\n` +
|
|
47
47
|
`Make sure the container is running: npm run test:db:start\n` +
|
|
48
48
|
`Check container status: docker ps | grep postgres-test\n` +
|
|
49
49
|
`View container logs: npm run test:db:logs\n` +
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { IOrganization, IUserContext, IUser } from "@loomcore/common/models";
|
|
1
|
+
import { IOrganization, IUserContext, IUser, IPersonModel } from "@loomcore/common/models";
|
|
2
2
|
export declare let TEST_META_ORG_ID: string | number;
|
|
3
3
|
export declare let TEST_META_ORG_USER_ID: string | number;
|
|
4
|
+
export declare let TEST_META_ORG_USER_PERSON_ID: string | number;
|
|
4
5
|
export declare function setTestMetaOrgId(metaOrgId: string | number): void;
|
|
5
6
|
export declare function setTestMetaOrgUserId(userId: string | number): void;
|
|
7
|
+
export declare function setTestMetaOrgUserPersonId(personId: string | number): void;
|
|
6
8
|
export declare const TEST_META_ORG_USER_PASSWORD = "test-meta-org-user-password";
|
|
7
9
|
export declare function getTestMetaOrg(): IOrganization;
|
|
8
10
|
export declare function getTestMetaOrgUser(): IUser;
|
|
11
|
+
export declare function getTestMetaOrgUserPerson(): IPersonModel;
|
|
9
12
|
export declare function getTestMetaOrgUserContext(): IUserContext;
|
|
10
13
|
export declare function setTestOrgId(orgId: string | number): void;
|
|
11
14
|
export declare function setTestOrgUserId(userId: string | number): void;
|
|
15
|
+
export declare function setTestOrgUserPersonId(personId: string | number): void;
|
|
12
16
|
export declare function getTestOrg(): IOrganization;
|
|
13
17
|
export declare const TEST_ORG_USER_PASSWORD = "test-org-user-password";
|
|
14
18
|
export declare function getTestOrgUser(): IUser;
|
|
19
|
+
export declare function getTestOrgUserPerson(): IPersonModel;
|
|
15
20
|
export declare function getTestOrgUserContext(): IUserContext;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export let TEST_META_ORG_ID = '69261691f936c45f85da24d0';
|
|
2
2
|
export let TEST_META_ORG_USER_ID = '69261672f48fb7bf76e54dfb';
|
|
3
|
+
export let TEST_META_ORG_USER_PERSON_ID = '69261672f48fb7bf76e54dfc';
|
|
3
4
|
export function setTestMetaOrgId(metaOrgId) {
|
|
4
5
|
TEST_META_ORG_ID = metaOrgId;
|
|
5
6
|
}
|
|
6
7
|
export function setTestMetaOrgUserId(userId) {
|
|
7
8
|
TEST_META_ORG_USER_ID = userId;
|
|
8
9
|
}
|
|
10
|
+
export function setTestMetaOrgUserPersonId(personId) {
|
|
11
|
+
TEST_META_ORG_USER_PERSON_ID = personId;
|
|
12
|
+
}
|
|
9
13
|
export const TEST_META_ORG_USER_PASSWORD = 'test-meta-org-user-password';
|
|
10
14
|
export function getTestMetaOrg() {
|
|
11
15
|
return {
|
|
@@ -25,9 +29,9 @@ export function getTestMetaOrgUser() {
|
|
|
25
29
|
return {
|
|
26
30
|
_id: TEST_META_ORG_USER_ID,
|
|
27
31
|
_orgId: getTestMetaOrg()._id,
|
|
32
|
+
externalId: 'test-meta-org-user-external-id',
|
|
33
|
+
personId: TEST_META_ORG_USER_PERSON_ID,
|
|
28
34
|
email: 'test@example.com',
|
|
29
|
-
firstName: 'Test',
|
|
30
|
-
lastName: 'User',
|
|
31
35
|
displayName: 'Test User',
|
|
32
36
|
password: TEST_META_ORG_USER_PASSWORD,
|
|
33
37
|
_created: new Date(),
|
|
@@ -36,6 +40,25 @@ export function getTestMetaOrgUser() {
|
|
|
36
40
|
_updatedBy: 'system',
|
|
37
41
|
};
|
|
38
42
|
}
|
|
43
|
+
export function getTestMetaOrgUserPerson() {
|
|
44
|
+
return {
|
|
45
|
+
_id: TEST_META_ORG_USER_PERSON_ID,
|
|
46
|
+
_orgId: getTestMetaOrg()._id,
|
|
47
|
+
externalId: 'test-meta-org-user-person-external-id',
|
|
48
|
+
middleName: null,
|
|
49
|
+
firstName: 'Test',
|
|
50
|
+
lastName: 'User',
|
|
51
|
+
isAgent: false,
|
|
52
|
+
isClient: false,
|
|
53
|
+
isEmployee: false,
|
|
54
|
+
dateOfBirth: null,
|
|
55
|
+
extendedTypes: 0,
|
|
56
|
+
_created: new Date(),
|
|
57
|
+
_createdBy: 'system',
|
|
58
|
+
_updated: new Date(),
|
|
59
|
+
_updatedBy: 'system',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
39
62
|
export function getTestMetaOrgUserContext() {
|
|
40
63
|
return {
|
|
41
64
|
user: getTestMetaOrgUser(),
|
|
@@ -52,12 +75,16 @@ export function getTestMetaOrgUserContext() {
|
|
|
52
75
|
;
|
|
53
76
|
let TEST_ORG_ID = '6926167d06c0073a778a124f';
|
|
54
77
|
let TEST_ORG_USER_ID = '6926167d06c0073a778a1250';
|
|
78
|
+
let TEST_ORG_USER_PERSON_ID = '6926167d06c0073a778a1251';
|
|
55
79
|
export function setTestOrgId(orgId) {
|
|
56
80
|
TEST_ORG_ID = orgId;
|
|
57
81
|
}
|
|
58
82
|
export function setTestOrgUserId(userId) {
|
|
59
83
|
TEST_ORG_USER_ID = userId;
|
|
60
84
|
}
|
|
85
|
+
export function setTestOrgUserPersonId(personId) {
|
|
86
|
+
TEST_ORG_USER_PERSON_ID = personId;
|
|
87
|
+
}
|
|
61
88
|
export function getTestOrg() {
|
|
62
89
|
return {
|
|
63
90
|
_id: TEST_ORG_ID,
|
|
@@ -77,9 +104,9 @@ export function getTestOrgUser() {
|
|
|
77
104
|
return {
|
|
78
105
|
_id: TEST_ORG_USER_ID,
|
|
79
106
|
_orgId: getTestOrg()._id,
|
|
107
|
+
externalId: 'test-org-user-external-id',
|
|
80
108
|
email: 'test-org-user@example.com',
|
|
81
|
-
|
|
82
|
-
lastName: 'User',
|
|
109
|
+
personId: TEST_ORG_USER_PERSON_ID,
|
|
83
110
|
displayName: 'Test User',
|
|
84
111
|
password: TEST_ORG_USER_PASSWORD,
|
|
85
112
|
_created: new Date(),
|
|
@@ -88,6 +115,25 @@ export function getTestOrgUser() {
|
|
|
88
115
|
_updatedBy: 'system',
|
|
89
116
|
};
|
|
90
117
|
}
|
|
118
|
+
export function getTestOrgUserPerson() {
|
|
119
|
+
return {
|
|
120
|
+
_id: TEST_ORG_USER_PERSON_ID,
|
|
121
|
+
_orgId: getTestOrg()._id,
|
|
122
|
+
externalId: 'test-org-user-person-external-id',
|
|
123
|
+
middleName: null,
|
|
124
|
+
firstName: 'Test',
|
|
125
|
+
lastName: 'User',
|
|
126
|
+
isAgent: false,
|
|
127
|
+
isClient: false,
|
|
128
|
+
isEmployee: false,
|
|
129
|
+
dateOfBirth: null,
|
|
130
|
+
extendedTypes: 0,
|
|
131
|
+
_created: new Date(),
|
|
132
|
+
_createdBy: 'system',
|
|
133
|
+
_updated: new Date(),
|
|
134
|
+
_updatedBy: 'system',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
91
137
|
export function getTestOrgUserContext() {
|
|
92
138
|
return {
|
|
93
139
|
user: getTestOrgUser(),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Application, Request, Response, NextFunction } from 'express';
|
|
2
2
|
import { AuthService } from '../services/index.js';
|
|
3
3
|
import { IDatabase } from '../databases/models/index.js';
|
|
4
|
+
import { PersonService } from '../services/person.service.js';
|
|
4
5
|
export declare class AuthController {
|
|
5
6
|
authService: AuthService;
|
|
7
|
+
personService: PersonService;
|
|
6
8
|
constructor(app: Application, database: IDatabase);
|
|
7
9
|
mapRoutes(app: Application): void;
|
|
8
10
|
login(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
@@ -4,10 +4,13 @@ import { BadRequestError, UnauthenticatedError } from '../errors/index.js';
|
|
|
4
4
|
import { apiUtils } from '../utils/index.js';
|
|
5
5
|
import { AuthService } from '../services/index.js';
|
|
6
6
|
import { isAuthorized } from '../middleware/index.js';
|
|
7
|
+
import { PersonService } from '../services/person.service.js';
|
|
7
8
|
export class AuthController {
|
|
8
9
|
authService;
|
|
10
|
+
personService;
|
|
9
11
|
constructor(app, database) {
|
|
10
12
|
this.authService = new AuthService(database);
|
|
13
|
+
this.personService = new PersonService(database);
|
|
11
14
|
this.mapRoutes(app);
|
|
12
15
|
}
|
|
13
16
|
mapRoutes(app) {
|
|
@@ -27,13 +30,15 @@ export class AuthController {
|
|
|
27
30
|
}
|
|
28
31
|
async registerUser(req, res) {
|
|
29
32
|
const userContext = req.userContext;
|
|
30
|
-
const body = req.body;
|
|
31
|
-
const validationErrors = this.authService.validate(body);
|
|
32
|
-
entityUtils.handleValidationResult(validationErrors, 'AuthController.registerUser');
|
|
33
33
|
if (!userContext) {
|
|
34
34
|
throw new BadRequestError('Missing required fields: userContext is required.');
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const body = req.body;
|
|
37
|
+
let validationErrors = this.authService.validate(body.user);
|
|
38
|
+
entityUtils.handleValidationResult(validationErrors, 'AuthController.registerUser');
|
|
39
|
+
validationErrors = this.personService.validate(body.person);
|
|
40
|
+
entityUtils.handleValidationResult(validationErrors, 'AuthController.registerUser');
|
|
41
|
+
const user = await this.authService.createUser(userContext, body.user, body.person);
|
|
37
42
|
apiUtils.apiResponse(res, 201, { data: user || undefined }, UserSpec, PublicUserSpec);
|
|
38
43
|
}
|
|
39
44
|
async requestTokenUsingRefreshToken(req, res, next) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
|
-
import { initializeSystemUserContext, EmptyUserContext, getSystemUserContext, isSystemUserContextInitialized } from '@loomcore/common/models';
|
|
2
|
+
import { initializeSystemUserContext, EmptyUserContext, getSystemUserContext, isSystemUserContextInitialized, personModelSpec } from '@loomcore/common/models';
|
|
3
3
|
import { MongoDBDatabase } from '../mongo-db.database.js';
|
|
4
|
-
import { AuthService, OrganizationService } from '../../../services/index.js';
|
|
4
|
+
import { AuthService, GenericApiService, OrganizationService } from '../../../services/index.js';
|
|
5
5
|
export const getMongoInitialSchema = (config) => {
|
|
6
6
|
const migrations = [];
|
|
7
7
|
const isMultiTenant = config.app.isMultiTenant;
|
|
@@ -167,6 +167,7 @@ export const getMongoInitialSchema = (config) => {
|
|
|
167
167
|
up: async ({ context: db }) => {
|
|
168
168
|
const database = new MongoDBDatabase(db);
|
|
169
169
|
const authService = new AuthService(database);
|
|
170
|
+
const personService = new GenericApiService(database, 'persons', 'person', personModelSpec);
|
|
170
171
|
if (!isSystemUserContextInitialized()) {
|
|
171
172
|
const errorMessage = isMultiTenant
|
|
172
173
|
? 'SystemUserContext has not been initialized. The meta-org migration (00000000000008_data-meta-org) should have run before this migration. ' +
|
|
@@ -178,15 +179,32 @@ export const getMongoInitialSchema = (config) => {
|
|
|
178
179
|
}
|
|
179
180
|
const systemUserContext = getSystemUserContext();
|
|
180
181
|
const _id = randomUUID().toString();
|
|
182
|
+
const personId = randomUUID().toString();
|
|
183
|
+
const person = {
|
|
184
|
+
_id: personId,
|
|
185
|
+
_orgId: systemUserContext.organization?._id,
|
|
186
|
+
externalId: 'admin-user-person-external-id',
|
|
187
|
+
middleName: null,
|
|
188
|
+
firstName: 'Admin',
|
|
189
|
+
lastName: 'User',
|
|
190
|
+
isAgent: false,
|
|
191
|
+
isClient: false,
|
|
192
|
+
isEmployee: false,
|
|
193
|
+
dateOfBirth: null,
|
|
194
|
+
extendedTypes: 0,
|
|
195
|
+
_created: new Date(),
|
|
196
|
+
_createdBy: 'system',
|
|
197
|
+
_updated: new Date(),
|
|
198
|
+
_updatedBy: 'system'
|
|
199
|
+
};
|
|
181
200
|
await authService.createUser(systemUserContext, {
|
|
182
201
|
_id: _id,
|
|
183
202
|
_orgId: systemUserContext.organization?._id,
|
|
203
|
+
externalId: 'admin-user-external-id',
|
|
184
204
|
email: config.auth?.adminUser?.email,
|
|
185
205
|
password: config.auth?.adminUser?.password,
|
|
186
|
-
firstName: 'Admin',
|
|
187
|
-
lastName: 'User',
|
|
188
206
|
displayName: 'Admin User',
|
|
189
|
-
});
|
|
207
|
+
}, person);
|
|
190
208
|
},
|
|
191
209
|
down: async ({ context: db }) => {
|
|
192
210
|
if (!config.auth?.adminUser?.email)
|
package/dist/databases/operations/__tests__/models/{agent.model.d.ts → test-agent.model.d.ts}
RENAMED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { IAuditable, IEntity } from "@loomcore/common/models";
|
|
2
|
-
import {
|
|
3
|
-
export interface
|
|
2
|
+
import { ITestPersonModel } from "./test-person.model.js";
|
|
3
|
+
export interface ITestAgentModel extends IEntity, IAuditable {
|
|
4
4
|
person_id: number;
|
|
5
|
-
agent_person?:
|
|
5
|
+
agent_person?: ITestPersonModel;
|
|
6
6
|
}
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const testAgentSchema: import("@sinclair/typebox").TObject<{
|
|
8
8
|
person_id: import("@sinclair/typebox").TNumber;
|
|
9
9
|
agent_person: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
10
10
|
first_name: import("@sinclair/typebox").TString;
|
|
11
11
|
middle_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
12
12
|
last_name: import("@sinclair/typebox").TString;
|
|
13
|
-
|
|
13
|
+
client_phone_numbers: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
14
14
|
phone_number: import("@sinclair/typebox").TString;
|
|
15
15
|
phone_number_type: import("@sinclair/typebox").TString;
|
|
16
16
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
17
17
|
}>>;
|
|
18
|
-
|
|
18
|
+
client_email_addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
19
19
|
person_id: import("@sinclair/typebox").TNumber;
|
|
20
20
|
email_address: import("@sinclair/typebox").TString;
|
|
21
21
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
22
22
|
}>>;
|
|
23
23
|
}>>;
|
|
24
24
|
}>;
|
|
25
|
-
export declare const
|
|
25
|
+
export declare const testAgentModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { entityUtils } from "@loomcore/common/utils";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { testPersonSchema } from "./test-person.model.js";
|
|
4
|
+
export const testAgentSchema = Type.Object({
|
|
5
|
+
person_id: Type.Number(),
|
|
6
|
+
agent_person: Type.Optional(testPersonSchema),
|
|
7
|
+
});
|
|
8
|
+
export const testAgentModelSpec = entityUtils.getModelSpec(testAgentSchema, { isAuditable: true });
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ITestPersonModel } from "./test-person.model.js";
|
|
2
|
+
import { ITestAgentModel } from "./test-agent.model.js";
|
|
3
|
+
import { ITestPolicyModel } from "./test-policy.model.js";
|
|
4
4
|
import type { IAuditable, IEntity } from "@loomcore/common/models";
|
|
5
|
-
export interface
|
|
6
|
-
client_person:
|
|
7
|
-
agent?:
|
|
8
|
-
|
|
5
|
+
export interface ITestClientReportsModel extends IEntity, IAuditable {
|
|
6
|
+
client_person: ITestPersonModel;
|
|
7
|
+
agent?: ITestAgentModel;
|
|
8
|
+
client_policies?: ITestPolicyModel[];
|
|
9
9
|
}
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const testClientReportsSchema: import("@sinclair/typebox").TObject<{
|
|
11
11
|
client_person: import("@sinclair/typebox").TObject<{
|
|
12
12
|
first_name: import("@sinclair/typebox").TString;
|
|
13
13
|
middle_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
14
14
|
last_name: import("@sinclair/typebox").TString;
|
|
15
|
-
|
|
15
|
+
client_phone_numbers: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
16
16
|
phone_number: import("@sinclair/typebox").TString;
|
|
17
17
|
phone_number_type: import("@sinclair/typebox").TString;
|
|
18
18
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
19
19
|
}>>;
|
|
20
|
-
|
|
20
|
+
client_email_addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
21
21
|
person_id: import("@sinclair/typebox").TNumber;
|
|
22
22
|
email_address: import("@sinclair/typebox").TString;
|
|
23
23
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
@@ -29,19 +29,19 @@ export declare const clientReportsSchema: import("@sinclair/typebox").TObject<{
|
|
|
29
29
|
first_name: import("@sinclair/typebox").TString;
|
|
30
30
|
middle_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
31
31
|
last_name: import("@sinclair/typebox").TString;
|
|
32
|
-
|
|
32
|
+
client_phone_numbers: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
33
33
|
phone_number: import("@sinclair/typebox").TString;
|
|
34
34
|
phone_number_type: import("@sinclair/typebox").TString;
|
|
35
35
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
36
36
|
}>>;
|
|
37
|
-
|
|
37
|
+
client_email_addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
38
38
|
person_id: import("@sinclair/typebox").TNumber;
|
|
39
39
|
email_address: import("@sinclair/typebox").TString;
|
|
40
40
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
41
41
|
}>>;
|
|
42
42
|
}>>;
|
|
43
43
|
}>>;
|
|
44
|
-
|
|
44
|
+
client_policies: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
45
45
|
client_id: import("@sinclair/typebox").TNumber;
|
|
46
46
|
amount: import("@sinclair/typebox").TNumber;
|
|
47
47
|
frequency: import("@sinclair/typebox").TString;
|
|
@@ -51,18 +51,23 @@ export declare const clientReportsSchema: import("@sinclair/typebox").TObject<{
|
|
|
51
51
|
first_name: import("@sinclair/typebox").TString;
|
|
52
52
|
middle_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
53
53
|
last_name: import("@sinclair/typebox").TString;
|
|
54
|
-
|
|
54
|
+
client_phone_numbers: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
55
55
|
phone_number: import("@sinclair/typebox").TString;
|
|
56
56
|
phone_number_type: import("@sinclair/typebox").TString;
|
|
57
57
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
58
58
|
}>>;
|
|
59
|
-
|
|
59
|
+
client_email_addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
60
60
|
person_id: import("@sinclair/typebox").TNumber;
|
|
61
61
|
email_address: import("@sinclair/typebox").TString;
|
|
62
62
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
63
63
|
}>>;
|
|
64
64
|
}>>;
|
|
65
65
|
}>>>;
|
|
66
|
+
policy_premiums: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
67
|
+
policy_id: import("@sinclair/typebox").TNumber;
|
|
68
|
+
amount: import("@sinclair/typebox").TNumber;
|
|
69
|
+
date: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TDate, import("@sinclair/typebox").TString]>;
|
|
70
|
+
}>>>;
|
|
66
71
|
}>>>;
|
|
67
72
|
}>;
|
|
68
|
-
export declare const
|
|
73
|
+
export declare const testClientReportsModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { testPersonSchema } from "./test-person.model.js";
|
|
2
|
+
import { testAgentSchema } from "./test-agent.model.js";
|
|
3
|
+
import { testPolicySchema } from "./test-policy.model.js";
|
|
4
|
+
import { entityUtils } from "@loomcore/common/utils";
|
|
5
|
+
import { Type } from "@sinclair/typebox";
|
|
6
|
+
export const testClientReportsSchema = Type.Object({
|
|
7
|
+
client_person: testPersonSchema,
|
|
8
|
+
agent: Type.Optional(testAgentSchema),
|
|
9
|
+
client_policies: Type.Optional(Type.Array(testPolicySchema))
|
|
10
|
+
});
|
|
11
|
+
export const testClientReportsModelSpec = entityUtils.getModelSpec(testClientReportsSchema, { isAuditable: true });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IAuditable, IEntity } from "@loomcore/common/models";
|
|
2
|
+
import { ITestStateModel } from "./test-state.model.js";
|
|
3
|
+
export interface ITestDistrictModel extends IEntity, IAuditable {
|
|
4
|
+
name: string;
|
|
5
|
+
state_id: number;
|
|
6
|
+
state?: ITestStateModel;
|
|
7
|
+
}
|
|
8
|
+
export declare const testDistrictSchema: import("@sinclair/typebox").TObject<{
|
|
9
|
+
name: import("@sinclair/typebox").TString;
|
|
10
|
+
state_id: import("@sinclair/typebox").TNumber;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const testDistrictModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
package/dist/databases/operations/__tests__/models/{district.model.js → test-district.model.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { entityUtils } from "@loomcore/common/utils";
|
|
2
2
|
import { Type } from "@sinclair/typebox";
|
|
3
|
-
export const
|
|
3
|
+
export const testDistrictSchema = Type.Object({
|
|
4
4
|
name: Type.String(),
|
|
5
5
|
state_id: Type.Number(),
|
|
6
6
|
});
|
|
7
|
-
export const
|
|
7
|
+
export const testDistrictModelSpec = entityUtils.getModelSpec(testDistrictSchema, { isAuditable: true });
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IAuditable, IEntity } from "@loomcore/common/models";
|
|
2
|
-
export interface
|
|
2
|
+
export interface ITestEmailAddressModel extends IEntity, IAuditable {
|
|
3
3
|
person_id: number;
|
|
4
4
|
email_address: string;
|
|
5
5
|
is_default: boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const testEmailAddressSchema: import("@sinclair/typebox").TObject<{
|
|
8
8
|
person_id: import("@sinclair/typebox").TNumber;
|
|
9
9
|
email_address: import("@sinclair/typebox").TString;
|
|
10
10
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
11
11
|
}>;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const testEmailAddressModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { entityUtils } from "@loomcore/common/utils";
|
|
2
2
|
import { Type } from "@sinclair/typebox";
|
|
3
|
-
export const
|
|
3
|
+
export const testEmailAddressSchema = Type.Object({
|
|
4
4
|
person_id: Type.Number(),
|
|
5
5
|
email_address: Type.String(),
|
|
6
6
|
is_default: Type.Boolean(),
|
|
7
7
|
});
|
|
8
|
-
export const
|
|
8
|
+
export const testEmailAddressModelSpec = entityUtils.getModelSpec(testEmailAddressSchema);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IAuditable, IEntity } from "@loomcore/common/models";
|
|
2
|
+
import { ITestEmailAddressModel } from "./test-email-address.model.js";
|
|
3
|
+
import { ITestPhoneNumberModel } from "./test-phone-number.model.js";
|
|
4
|
+
import { ITestSchoolModel } from "./test-school.model.js";
|
|
5
|
+
export interface ITestPersonModel extends IEntity, IAuditable {
|
|
6
|
+
first_name: string;
|
|
7
|
+
middle_name: string | null;
|
|
8
|
+
last_name: string;
|
|
9
|
+
client_email_addresses: ITestEmailAddressModel[];
|
|
10
|
+
client_phone_numbers: ITestPhoneNumberModel[];
|
|
11
|
+
school?: ITestSchoolModel;
|
|
12
|
+
}
|
|
13
|
+
export declare const testPersonSchema: import("@sinclair/typebox").TObject<{
|
|
14
|
+
first_name: import("@sinclair/typebox").TString;
|
|
15
|
+
middle_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
16
|
+
last_name: import("@sinclair/typebox").TString;
|
|
17
|
+
client_phone_numbers: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
18
|
+
phone_number: import("@sinclair/typebox").TString;
|
|
19
|
+
phone_number_type: import("@sinclair/typebox").TString;
|
|
20
|
+
is_default: import("@sinclair/typebox").TBoolean;
|
|
21
|
+
}>>;
|
|
22
|
+
client_email_addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
23
|
+
person_id: import("@sinclair/typebox").TNumber;
|
|
24
|
+
email_address: import("@sinclair/typebox").TString;
|
|
25
|
+
is_default: import("@sinclair/typebox").TBoolean;
|
|
26
|
+
}>>;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const testPersonModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { entityUtils } from "@loomcore/common/utils";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { testEmailAddressSchema } from "./test-email-address.model.js";
|
|
4
|
+
import { testPhoneNumberSchema } from "./test-phone-number.model.js";
|
|
5
|
+
export const testPersonSchema = Type.Object({
|
|
6
|
+
first_name: Type.String(),
|
|
7
|
+
middle_name: Type.Optional(Type.String()),
|
|
8
|
+
last_name: Type.String(),
|
|
9
|
+
client_phone_numbers: Type.Array(testPhoneNumberSchema),
|
|
10
|
+
client_email_addresses: Type.Array(testEmailAddressSchema),
|
|
11
|
+
});
|
|
12
|
+
export const testPersonModelSpec = entityUtils.getModelSpec(testPersonSchema, { isAuditable: true });
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IAuditable, IEntity } from "@loomcore/common/models";
|
|
2
|
-
export interface
|
|
2
|
+
export interface ITestPhoneNumberModel extends IEntity, IAuditable {
|
|
3
3
|
phone_number: string;
|
|
4
4
|
phone_number_type: string;
|
|
5
5
|
is_default: boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const testPhoneNumberSchema: import("@sinclair/typebox").TObject<{
|
|
8
8
|
phone_number: import("@sinclair/typebox").TString;
|
|
9
9
|
phone_number_type: import("@sinclair/typebox").TString;
|
|
10
10
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
11
11
|
}>;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const testPhoneNumberModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { entityUtils } from "@loomcore/common/utils";
|
|
2
2
|
import { Type } from "@sinclair/typebox";
|
|
3
|
-
export const
|
|
3
|
+
export const testPhoneNumberSchema = Type.Object({
|
|
4
4
|
phone_number: Type.String(),
|
|
5
5
|
phone_number_type: Type.String(),
|
|
6
6
|
is_default: Type.Boolean(),
|
|
7
7
|
});
|
|
8
|
-
export const
|
|
8
|
+
export const testPhoneNumberModelSpec = entityUtils.getModelSpec(testPhoneNumberSchema, { isAuditable: true });
|
package/dist/databases/operations/__tests__/models/{policy.model.d.ts → test-policy.model.d.ts}
RENAMED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { IAuditable, IEntity } from "@loomcore/common/models";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ITestAgentModel } from "./test-agent.model.js";
|
|
3
|
+
import { ITestPremiumModel } from "./test-premium.model.js";
|
|
4
|
+
export interface ITestPolicyModel extends IEntity, IAuditable {
|
|
4
5
|
client_id: number;
|
|
5
6
|
amount: number;
|
|
6
7
|
frequency: string;
|
|
7
|
-
agents?:
|
|
8
|
+
agents?: ITestAgentModel[];
|
|
9
|
+
policy_premiums?: ITestPremiumModel[];
|
|
8
10
|
}
|
|
9
|
-
export declare const
|
|
11
|
+
export declare const testPolicySchema: import("@sinclair/typebox").TObject<{
|
|
10
12
|
client_id: import("@sinclair/typebox").TNumber;
|
|
11
13
|
amount: import("@sinclair/typebox").TNumber;
|
|
12
14
|
frequency: import("@sinclair/typebox").TString;
|
|
@@ -16,17 +18,22 @@ export declare const policySchema: import("@sinclair/typebox").TObject<{
|
|
|
16
18
|
first_name: import("@sinclair/typebox").TString;
|
|
17
19
|
middle_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
18
20
|
last_name: import("@sinclair/typebox").TString;
|
|
19
|
-
|
|
21
|
+
client_phone_numbers: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
20
22
|
phone_number: import("@sinclair/typebox").TString;
|
|
21
23
|
phone_number_type: import("@sinclair/typebox").TString;
|
|
22
24
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
23
25
|
}>>;
|
|
24
|
-
|
|
26
|
+
client_email_addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
25
27
|
person_id: import("@sinclair/typebox").TNumber;
|
|
26
28
|
email_address: import("@sinclair/typebox").TString;
|
|
27
29
|
is_default: import("@sinclair/typebox").TBoolean;
|
|
28
30
|
}>>;
|
|
29
31
|
}>>;
|
|
30
32
|
}>>>;
|
|
33
|
+
policy_premiums: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
34
|
+
policy_id: import("@sinclair/typebox").TNumber;
|
|
35
|
+
amount: import("@sinclair/typebox").TNumber;
|
|
36
|
+
date: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TDate, import("@sinclair/typebox").TString]>;
|
|
37
|
+
}>>>;
|
|
31
38
|
}>;
|
|
32
|
-
export declare const
|
|
39
|
+
export declare const testPolicyModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|