@loomcore/api 0.1.81 → 0.1.85
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/dist/__tests__/common-test.utils.js +16 -5
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +0 -29
- package/dist/__tests__/test-express-app.d.ts +0 -1
- package/dist/__tests__/test-express-app.js +0 -1
- package/dist/__tests__/test-objects.js +2 -7
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +0 -3
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +1 -1
- package/dist/databases/postgres/utils/index.d.ts +4 -0
- package/dist/databases/postgres/utils/index.js +4 -0
- package/package.json +2 -2
|
@@ -19,15 +19,18 @@ import { setBaseApiConfig, config } from '../config/index.js';
|
|
|
19
19
|
import { entityUtils } from '@loomcore/common/utils';
|
|
20
20
|
import { getTestMetaOrgUserPerson, getTestOrgUser, getTestOrgUserPerson, setTestMetaOrgUserPersonId, setTestOrgUserPersonId } from './test-objects.js';
|
|
21
21
|
import { TestEmailClient } from './test-email-client.js';
|
|
22
|
+
import { PersonService } from '../services/person.service.js';
|
|
22
23
|
let deviceIdCookie;
|
|
23
24
|
let authService;
|
|
24
25
|
let organizationService;
|
|
26
|
+
let personService;
|
|
25
27
|
const JWT_SECRET = 'test-secret';
|
|
26
28
|
const newUser1Email = 'one@test.com';
|
|
27
29
|
const newUser1Password = 'testone';
|
|
28
30
|
const constDeviceIdCookie = crypto.randomBytes(16).toString('hex');
|
|
29
31
|
function initialize(database) {
|
|
30
32
|
authService = new AuthService(database);
|
|
33
|
+
personService = new PersonService(database);
|
|
31
34
|
organizationService = new OrganizationService(database);
|
|
32
35
|
deviceIdCookie = constDeviceIdCookie;
|
|
33
36
|
}
|
|
@@ -90,7 +93,7 @@ async function setupTestUsers() {
|
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
async function createTestUsers() {
|
|
93
|
-
if (!authService || !organizationService) {
|
|
96
|
+
if (!authService || !organizationService || !personService) {
|
|
94
97
|
throw new Error('Database not initialized. Call initialize() first.');
|
|
95
98
|
}
|
|
96
99
|
try {
|
|
@@ -110,15 +113,23 @@ async function createTestUsers() {
|
|
|
110
113
|
else {
|
|
111
114
|
setTestOrgId(existingTestOrg._id);
|
|
112
115
|
}
|
|
113
|
-
const
|
|
114
|
-
|
|
116
|
+
const createdTestOrgUserPerson = await personService.create(getTestOrgUserContext(), getTestOrgUserPerson());
|
|
117
|
+
if (!createdTestOrgUserPerson) {
|
|
118
|
+
throw new Error('Failed to create test organization user person');
|
|
119
|
+
}
|
|
120
|
+
setTestOrgUserPersonId(createdTestOrgUserPerson._id);
|
|
121
|
+
const createdMetaOrgUserPerson = await personService.create(getTestMetaOrgUserContext(), getTestMetaOrgUserPerson());
|
|
122
|
+
if (!createdMetaOrgUserPerson) {
|
|
123
|
+
throw new Error('Failed to create meta organization user person');
|
|
124
|
+
}
|
|
125
|
+
setTestMetaOrgUserPersonId(createdMetaOrgUserPerson._id);
|
|
126
|
+
const createdTestOrgUser = await authService.createUser(getTestOrgUserContext(), getTestOrgUser());
|
|
127
|
+
const createdMetaOrgUser = await authService.createUser(getTestMetaOrgUserContext(), getTestMetaOrgUser());
|
|
115
128
|
if (!createdTestOrgUser || !createdMetaOrgUser) {
|
|
116
129
|
throw new Error('Failed to create test user');
|
|
117
130
|
}
|
|
118
131
|
setTestMetaOrgUserId(createdMetaOrgUser._id);
|
|
119
|
-
setTestMetaOrgUserPersonId(createdMetaOrgUser.personId);
|
|
120
132
|
setTestOrgUserId(createdTestOrgUser._id);
|
|
121
|
-
setTestOrgUserPersonId(createdTestOrgUser.personId);
|
|
122
133
|
return { metaOrgUser: createdMetaOrgUser, testOrgUser: createdTestOrgUser };
|
|
123
134
|
}
|
|
124
135
|
catch (error) {
|
|
@@ -93,35 +93,6 @@ export const getPostgresTestSchema = (config) => {
|
|
|
93
93
|
await pool.query('DROP TABLE IF EXISTS "testItems"');
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
migrations.push({
|
|
97
|
-
name: '00000000000105_schema-persons',
|
|
98
|
-
up: async ({ context: pool }) => {
|
|
99
|
-
const orgColumnDef = isMultiTenant ? '"_orgId" INTEGER,' : '';
|
|
100
|
-
await pool.query(`
|
|
101
|
-
CREATE TABLE IF NOT EXISTS "persons" (
|
|
102
|
-
"_id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
103
|
-
${orgColumnDef}
|
|
104
|
-
"external_id" VARCHAR UNIQUE,
|
|
105
|
-
"is_agent" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
106
|
-
"is_client" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
107
|
-
"is_employee" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
108
|
-
"first_name" VARCHAR NOT NULL,
|
|
109
|
-
"middle_name" VARCHAR,
|
|
110
|
-
"date_of_birth" DATE,
|
|
111
|
-
"last_name" VARCHAR NOT NULL,
|
|
112
|
-
"_created" TIMESTAMPTZ NOT NULL,
|
|
113
|
-
"_createdBy" INTEGER NOT NULL,
|
|
114
|
-
"_updated" TIMESTAMPTZ NOT NULL,
|
|
115
|
-
"_updatedBy" INTEGER NOT NULL,
|
|
116
|
-
"_deleted" TIMESTAMPTZ,
|
|
117
|
-
"_deletedBy" INTEGER
|
|
118
|
-
)
|
|
119
|
-
`);
|
|
120
|
-
},
|
|
121
|
-
down: async ({ context: pool }) => {
|
|
122
|
-
await pool.query('DROP TABLE IF EXISTS "persons"');
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
96
|
migrations.push({
|
|
126
97
|
name: '00000000000105_5_schema-agents',
|
|
127
98
|
up: async ({ context: pool }) => {
|
|
@@ -41,23 +41,21 @@ export function getTestMetaOrgUser() {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
export function getTestMetaOrgUserPerson() {
|
|
44
|
-
|
|
44
|
+
const person = {
|
|
45
45
|
_id: TEST_META_ORG_USER_PERSON_ID,
|
|
46
46
|
_orgId: getTestMetaOrg()._id,
|
|
47
47
|
externalId: 'test-meta-org-user-person-external-id',
|
|
48
|
-
middleName: null,
|
|
49
48
|
firstName: 'Test',
|
|
50
49
|
lastName: 'User',
|
|
51
50
|
isAgent: false,
|
|
52
51
|
isClient: false,
|
|
53
52
|
isEmployee: false,
|
|
54
|
-
dateOfBirth: null,
|
|
55
|
-
extendedTypes: 0,
|
|
56
53
|
_created: new Date(),
|
|
57
54
|
_createdBy: 'system',
|
|
58
55
|
_updated: new Date(),
|
|
59
56
|
_updatedBy: 'system',
|
|
60
57
|
};
|
|
58
|
+
return person;
|
|
61
59
|
}
|
|
62
60
|
export function getTestMetaOrgUserContext() {
|
|
63
61
|
return {
|
|
@@ -120,14 +118,11 @@ export function getTestOrgUserPerson() {
|
|
|
120
118
|
_id: TEST_ORG_USER_PERSON_ID,
|
|
121
119
|
_orgId: getTestOrg()._id,
|
|
122
120
|
externalId: 'test-org-user-person-external-id',
|
|
123
|
-
middleName: null,
|
|
124
121
|
firstName: 'Test',
|
|
125
122
|
lastName: 'User',
|
|
126
123
|
isAgent: false,
|
|
127
124
|
isClient: false,
|
|
128
125
|
isEmployee: false,
|
|
129
|
-
dateOfBirth: null,
|
|
130
|
-
extendedTypes: 0,
|
|
131
126
|
_created: new Date(),
|
|
132
127
|
_createdBy: 'system',
|
|
133
128
|
_updated: new Date(),
|
|
@@ -184,14 +184,11 @@ export const getMongoInitialSchema = (config) => {
|
|
|
184
184
|
_id: personId,
|
|
185
185
|
_orgId: systemUserContext.organization?._id,
|
|
186
186
|
externalId: 'admin-user-person-external-id',
|
|
187
|
-
middleName: null,
|
|
188
187
|
firstName: 'Admin',
|
|
189
188
|
lastName: 'User',
|
|
190
189
|
isAgent: false,
|
|
191
190
|
isClient: false,
|
|
192
191
|
isEmployee: false,
|
|
193
|
-
dateOfBirth: null,
|
|
194
|
-
extendedTypes: 0,
|
|
195
192
|
_created: new Date(),
|
|
196
193
|
_createdBy: 'system',
|
|
197
194
|
_updated: new Date(),
|
|
@@ -58,7 +58,7 @@ export const getPostgresInitialSchema = (config) => {
|
|
|
58
58
|
"isAgent" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
59
59
|
"isClient" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
60
60
|
"isEmployee" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
61
|
-
"extendedTypes" INTEGER
|
|
61
|
+
"extendedTypes" INTEGER,
|
|
62
62
|
"_created" TIMESTAMPTZ NOT NULL,
|
|
63
63
|
"_createdBy" INTEGER NOT NULL,
|
|
64
64
|
"_updated" TIMESTAMPTZ NOT NULL,
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './build-postgres-url.util.js';
|
|
2
2
|
export * from './does-table-exist.util.js';
|
|
3
|
+
export * from './build-where-clause.js';
|
|
4
|
+
export * from './build-pagination-clause.js';
|
|
5
|
+
export * from './build-order-by-clause.js';
|
|
6
|
+
export * from './convert-null-to-undefined.util.js';
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './build-postgres-url.util.js';
|
|
2
2
|
export * from './does-table-exist.util.js';
|
|
3
|
+
export * from './build-where-clause.js';
|
|
4
|
+
export * from './build-pagination-clause.js';
|
|
5
|
+
export * from './build-order-by-clause.js';
|
|
6
|
+
export * from './convert-null-to-undefined.util.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcore/api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.85",
|
|
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": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"qs": "^6.14.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@loomcore/common": "^0.0.
|
|
60
|
+
"@loomcore/common": "^0.0.49",
|
|
61
61
|
"@sinclair/typebox": "0.34.33",
|
|
62
62
|
"cookie-parser": "^1.4.6",
|
|
63
63
|
"cors": "^2.8.5",
|