@proconnect-gouv/proconnect.identite 10.0.2 → 10.2.0
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/CHANGELOG.md +18 -0
- package/dist/connectors/index.d.ts +87 -45
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +31 -53
- package/dist/managers/organization/adapters/api_entreprise.d.ts +3 -3
- package/dist/managers/organization/adapters/api_entreprise.d.ts.map +1 -1
- package/dist/managers/organization/adapters/api_entreprise.js +30 -27
- package/dist/managers/organization/adapters/index.d.ts +1 -0
- package/dist/managers/organization/adapters/index.d.ts.map +1 -1
- package/dist/managers/organization/adapters/index.js +1 -0
- package/dist/managers/organization/adapters/rne.d.ts +4 -0
- package/dist/managers/organization/adapters/rne.d.ts.map +1 -0
- package/dist/managers/organization/adapters/rne.js +7 -0
- package/dist/managers/organization/get-organization-info.d.ts +2 -1
- package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
- package/dist/managers/organization/get-organization-info.js +27 -7
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +1 -1
- package/dist/managers/user/assign-user-verification-type-to-domain.js +3 -3
- package/dist/repositories/authenticator/find-authenticators-by-user-id.d.ts +3 -0
- package/dist/repositories/authenticator/find-authenticators-by-user-id.d.ts.map +1 -0
- package/dist/repositories/authenticator/{get-authenticators-by-user-id.js → find-authenticators-by-user-id.js} +2 -2
- package/dist/repositories/authenticator/index.d.ts +1 -1
- package/dist/repositories/authenticator/index.d.ts.map +1 -1
- package/dist/repositories/authenticator/index.js +1 -1
- package/dist/repositories/authenticator/update-authenticator.d.ts +1 -2
- package/dist/repositories/authenticator/update-authenticator.d.ts.map +1 -1
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts +4 -0
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/{user → franceconnect_userinfo}/delete-franceconnect-userinfo.js +2 -2
- package/dist/repositories/{user/get-franceconnect-user-info.d.ts → franceconnect_userinfo/find-franceconnect-userinfo.d.ts} +2 -3
- package/dist/repositories/franceconnect_userinfo/find-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/{user/get-franceconnect-user-info.js → franceconnect_userinfo/find-franceconnect-userinfo.js} +2 -2
- package/dist/repositories/franceconnect_userinfo/index.d.ts +4 -0
- package/dist/repositories/franceconnect_userinfo/index.d.ts.map +1 -0
- package/dist/repositories/franceconnect_userinfo/index.js +3 -0
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.d.ts +3 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.js +12 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.d.ts +10 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.js +13 -0
- package/dist/repositories/official-contact-email-verification/index.d.ts +4 -0
- package/dist/repositories/official-contact-email-verification/index.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/index.js +4 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.d.ts +10 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.js +19 -0
- package/dist/repositories/organization/find-by-user-id.d.ts +0 -3
- package/dist/repositories/organization/find-by-user-id.d.ts.map +1 -1
- package/dist/repositories/organization/find-by-user-id.js +10 -14
- package/dist/repositories/organization/find-organization-by-id.d.ts +4 -0
- package/dist/repositories/organization/find-organization-by-id.d.ts.map +1 -0
- package/dist/repositories/organization/{find-by-id.js → find-organization-by-id.js} +2 -2
- package/dist/repositories/organization/{get-users-by-organization.d.ts → find-users-by-organization.d.ts} +2 -6
- package/dist/repositories/organization/find-users-by-organization.d.ts.map +1 -0
- package/dist/repositories/organization/find-users-by-organization.js +19 -0
- package/dist/repositories/organization/get-organization-by-id.d.ts +3 -0
- package/dist/repositories/organization/get-organization-by-id.d.ts.map +1 -0
- package/dist/repositories/organization/get-organization-by-id.js +15 -0
- package/dist/repositories/organization/index.d.ts +3 -5
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +3 -5
- package/dist/repositories/organization/upsert.d.ts.map +1 -1
- package/dist/repositories/organization/upsert.js +8 -3
- package/dist/repositories/user/index.d.ts +0 -3
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +0 -3
- package/dist/repositories/{organization/link-user-to-organization.d.ts → user_organisation/create-user-organization.d.ts} +2 -6
- package/dist/repositories/user_organisation/create-user-organization.d.ts.map +1 -0
- package/dist/repositories/{organization/link-user-to-organization.js → user_organisation/create-user-organization.js} +2 -3
- package/dist/repositories/user_organisation/delete-user-organization.d.ts +3 -0
- package/dist/repositories/user_organisation/delete-user-organization.d.ts.map +1 -0
- package/dist/repositories/{organization → user_organisation}/delete-user-organization.js +4 -2
- package/dist/repositories/{organization/get-user-organization-link.d.ts → user_organisation/find-user-organization.d.ts} +3 -6
- package/dist/repositories/user_organisation/find-user-organization.d.ts.map +1 -0
- package/dist/repositories/user_organisation/find-user-organization.js +20 -0
- package/dist/repositories/user_organisation/index.d.ts +5 -0
- package/dist/repositories/user_organisation/index.d.ts.map +1 -0
- package/dist/repositories/user_organisation/index.js +4 -0
- package/dist/repositories/{user/update-user-organization-link.d.ts → user_organisation/update-user-organization.d.ts} +3 -7
- package/dist/repositories/user_organisation/update-user-organization.d.ts.map +1 -0
- package/dist/repositories/{user/update-user-organization-link.js → user_organisation/update-user-organization.js} +2 -2
- package/dist/types/authenticator.d.ts +3 -1
- package/dist/types/authenticator.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/official-contact-email-verification.d.ts +23 -0
- package/dist/types/official-contact-email-verification.d.ts.map +1 -0
- package/dist/types/official-contact-email-verification.js +15 -0
- package/dist/types/organization-info.d.ts +10 -3
- package/dist/types/organization-info.d.ts.map +1 -1
- package/dist/types/organization-info.js +5 -1
- package/dist/types/organization.d.ts +2 -1
- package/dist/types/organization.d.ts.map +1 -1
- package/dist/types/user-organization-link.d.ts +5 -7
- package/dist/types/user-organization-link.d.ts.map +1 -1
- package/dist/types/user-organization-link.js +4 -6
- package/package.json +5 -5
- package/src/connectors/index.ts +83 -53
- package/src/managers/organization/adapters/api_entreprise.test.ts +6 -6
- package/src/managers/organization/adapters/api_entreprise.test.ts.snapshot +4 -4
- package/src/managers/organization/adapters/api_entreprise.ts +41 -31
- package/src/managers/organization/adapters/index.ts +1 -0
- package/src/managers/organization/adapters/rne.ts +14 -0
- package/src/managers/organization/get-organization-info.test.ts +66 -19
- package/src/managers/organization/get-organization-info.test.ts.snapshot +31 -3
- package/src/managers/organization/get-organization-info.ts +44 -13
- package/src/managers/organization/mark-domain-as-verified.test.ts +2 -3
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +7 -8
- package/src/managers/user/assign-user-verification-type-to-domain.ts +8 -5
- package/src/repositories/authenticator/{get-authenticators-by-user-id.test.ts → find-authenticators-by-user-id.test.ts} +5 -5
- package/src/repositories/authenticator/{get-authenticators-by-user-id.ts → find-authenticators-by-user-id.ts} +2 -2
- package/src/repositories/authenticator/index.ts +1 -1
- package/src/repositories/authenticator/update-authenticator.ts +1 -1
- package/src/repositories/{user → franceconnect_userinfo}/delete-franceconnect-userinfo.test.ts +7 -7
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.ts +21 -0
- package/src/repositories/{user/get-franceconnect-user-info.test.ts → franceconnect_userinfo/find-franceconnect-userinfo.test.ts} +5 -5
- package/src/repositories/{user/get-franceconnect-user-info.ts → franceconnect_userinfo/find-franceconnect-userinfo.ts} +2 -6
- package/src/repositories/franceconnect_userinfo/index.ts +3 -0
- package/src/repositories/official-contact-email-verification/delete-official-contact-email-verification.test.ts +106 -0
- package/src/repositories/official-contact-email-verification/delete-official-contact-email-verification.ts +29 -0
- package/src/repositories/official-contact-email-verification/find-official-contact-email-verification.test.ts +136 -0
- package/src/repositories/official-contact-email-verification/find-official-contact-email-verification.ts +31 -0
- package/src/repositories/official-contact-email-verification/index.ts +5 -0
- package/src/repositories/official-contact-email-verification/upsert-official-contact-email-verification.test.ts +170 -0
- package/src/repositories/official-contact-email-verification/upsert-official-contact-email-verification.ts +38 -0
- package/src/repositories/organization/find-by-user-id.test.ts +5 -6
- package/src/repositories/organization/find-by-user-id.test.ts.snapshot +6 -12
- package/src/repositories/organization/find-by-user-id.ts +10 -14
- package/src/repositories/organization/{find-by-id.test.ts → find-organization-by-id.test.ts} +5 -4
- package/src/repositories/organization/{find-by-id.ts → find-organization-by-id.ts} +3 -3
- package/src/repositories/organization/{get-users-by-organization.test.ts → find-users-by-organization.test.ts} +9 -8
- package/src/repositories/organization/{get-users-by-organization.test.ts.snapshot → find-users-by-organization.test.ts.snapshot} +2 -5
- package/src/repositories/organization/find-users-by-organization.ts +38 -0
- package/src/repositories/organization/get-organization-by-id.test.ts +37 -0
- package/src/repositories/organization/get-organization-by-id.ts +19 -0
- package/src/repositories/organization/index.ts +3 -5
- package/src/repositories/organization/upsert.ts +9 -1
- package/src/repositories/organization/upset.test.ts +2 -0
- package/src/repositories/user/index.ts +0 -3
- package/src/repositories/{organization/link-user-to-organization.test.ts → user_organisation/create-user-organization.test.ts} +2 -2
- package/src/repositories/{organization/link-user-to-organization.test.ts.snapshot → user_organisation/create-user-organization.test.ts.snapshot} +0 -6
- package/src/repositories/{organization/link-user-to-organization.ts → user_organisation/create-user-organization.ts} +1 -7
- package/src/repositories/{organization → user_organisation}/delete-user-organization.ts +6 -7
- package/src/repositories/{organization/get-user-organization-link.test.ts → user_organisation/find-user-organization.test.ts} +5 -5
- package/src/repositories/user_organisation/find-user-organization.ts +35 -0
- package/src/repositories/user_organisation/index.ts +4 -0
- package/src/repositories/{user/update-user-organization-link.test.ts → user_organisation/update-user-organization.test.ts} +10 -8
- package/src/repositories/{user/update-user-organization-link.ts → user_organisation/update-user-organization.ts} +9 -9
- package/src/services/organization/compute-service-public-info.test.ts +10 -0
- package/src/types/authenticator.ts +10 -5
- package/src/types/index.ts +1 -0
- package/src/types/official-contact-email-verification.ts +32 -0
- package/src/types/organization-info.ts +14 -3
- package/src/types/organization.ts +19 -1
- package/src/types/user-organization-link.ts +9 -8
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts +0 -3
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts.map +0 -1
- package/dist/repositories/organization/delete-user-organization.d.ts +0 -6
- package/dist/repositories/organization/delete-user-organization.d.ts.map +0 -1
- package/dist/repositories/organization/find-by-id.d.ts +0 -4
- package/dist/repositories/organization/find-by-id.d.ts.map +0 -1
- package/dist/repositories/organization/get-user-organization-link.d.ts.map +0 -1
- package/dist/repositories/organization/get-user-organization-link.js +0 -23
- package/dist/repositories/organization/get-users-by-organization.d.ts.map +0 -1
- package/dist/repositories/organization/get-users-by-organization.js +0 -23
- package/dist/repositories/organization/link-user-to-organization.d.ts.map +0 -1
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts +0 -4
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/user/get-franceconnect-user-info.d.ts.map +0 -1
- package/dist/repositories/user/update-user-organization-link.d.ts.map +0 -1
- package/dist/repositories/user/upsert-franceconnect-userinfo.d.ts.map +0 -1
- package/src/repositories/organization/get-user-organization-link.ts +0 -34
- package/src/repositories/organization/get-users-by-organization.ts +0 -46
- package/src/repositories/user/delete-franceconnect-userinfo.ts +0 -21
- package/tsconfig.lib.tsbuildinfo +0 -1
- /package/dist/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.d.ts +0 -0
- /package/dist/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.js +0 -0
- /package/src/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.test.ts +0 -0
- /package/src/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.ts +0 -0
- /package/src/repositories/{organization → user_organisation}/delete-user-organization.test.ts +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { deleteOfficialContactEmailVerificationFactory } from "./delete-official-contact-email-verification.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const deleteOfficialContactEmailVerification =
|
|
11
|
+
deleteOfficialContactEmailVerificationFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("deleteOfficialContactEmailVerificationFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should return true when the verification exists", async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO organizations
|
|
20
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
21
|
+
VALUES
|
|
22
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO users
|
|
27
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
28
|
+
VALUES
|
|
29
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
await pg.sql`
|
|
33
|
+
INSERT INTO official_contact_email_verifications
|
|
34
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
35
|
+
VALUES
|
|
36
|
+
(1, 1, '666666', '4444-04-04', '4444-04-04', '4444-04-04')
|
|
37
|
+
;
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const result = await deleteOfficialContactEmailVerification({
|
|
41
|
+
organization_id: 1,
|
|
42
|
+
user_id: 1,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
assert.equal(result, true);
|
|
46
|
+
|
|
47
|
+
const { rows } = await pg.sql`
|
|
48
|
+
SELECT count(*)::int AS count FROM official_contact_email_verifications;
|
|
49
|
+
`;
|
|
50
|
+
assert.deepEqual(rows, [{ count: 0 }]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("should return false when the verification does not exist", async () => {
|
|
54
|
+
const result = await deleteOfficialContactEmailVerification({
|
|
55
|
+
organization_id: 42,
|
|
56
|
+
user_id: 42,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
assert.equal(result, false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("should only delete the verification of the given user and organization", async () => {
|
|
63
|
+
await pg.sql`
|
|
64
|
+
INSERT INTO organizations
|
|
65
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
66
|
+
VALUES
|
|
67
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19'),
|
|
68
|
+
('Ultramar', 'Ultramarines', 2, '🔵', '1967-12-19', '1967-12-19')
|
|
69
|
+
;
|
|
70
|
+
`;
|
|
71
|
+
await pg.sql`
|
|
72
|
+
INSERT INTO users
|
|
73
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
74
|
+
VALUES
|
|
75
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'),
|
|
76
|
+
(2, 'roboute.guilliman@ultramarines.world', '4444-04-04', '4444-04-04', 'roboute', 'guilliman', 'xiii', 'primarque')
|
|
77
|
+
;
|
|
78
|
+
`;
|
|
79
|
+
await pg.sql`
|
|
80
|
+
INSERT INTO official_contact_email_verifications
|
|
81
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
82
|
+
VALUES
|
|
83
|
+
(1, 1, '111111', '4444-04-04', '4444-04-04', '4444-04-04'),
|
|
84
|
+
(1, 2, '222222', '4444-04-04', '4444-04-04', '4444-04-04'),
|
|
85
|
+
(2, 1, '333333', '4444-04-04', '4444-04-04', '4444-04-04')
|
|
86
|
+
;
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
const result = await deleteOfficialContactEmailVerification({
|
|
90
|
+
organization_id: 1,
|
|
91
|
+
user_id: 1,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
assert.equal(result, true);
|
|
95
|
+
|
|
96
|
+
const { rows } = await pg.sql`
|
|
97
|
+
SELECT user_id, organization_id, token
|
|
98
|
+
FROM official_contact_email_verifications
|
|
99
|
+
ORDER BY user_id, organization_id;
|
|
100
|
+
`;
|
|
101
|
+
assert.deepEqual(rows, [
|
|
102
|
+
{ user_id: 1, organization_id: 2, token: "222222" },
|
|
103
|
+
{ user_id: 2, organization_id: 1, token: "333333" },
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DatabaseContext,
|
|
5
|
+
FindOfficialContactEmailVerification,
|
|
6
|
+
} from "#src/types";
|
|
7
|
+
import type { QueryResult } from "pg";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
export function deleteOfficialContactEmailVerificationFactory({
|
|
12
|
+
pg,
|
|
13
|
+
}: DatabaseContext) {
|
|
14
|
+
return async function deleteOfficialContactEmailVerification({
|
|
15
|
+
user_id,
|
|
16
|
+
organization_id,
|
|
17
|
+
}: FindOfficialContactEmailVerification) {
|
|
18
|
+
const { rowCount, affectedRows } = (await pg.query(
|
|
19
|
+
`
|
|
20
|
+
DELETE
|
|
21
|
+
FROM official_contact_email_verifications
|
|
22
|
+
WHERE user_id = $1
|
|
23
|
+
AND organization_id = $2`,
|
|
24
|
+
[user_id, organization_id],
|
|
25
|
+
)) as QueryResult & { affectedRows?: number };
|
|
26
|
+
|
|
27
|
+
return (affectedRows ?? rowCount ?? 0) > 0;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { findOfficialContactEmailVerificationFactory } from "./find-official-contact-email-verification.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const findOfficialContactEmailVerification =
|
|
11
|
+
findOfficialContactEmailVerificationFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("findOfficialContactEmailVerificationFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should return undefined when not found", async () => {
|
|
18
|
+
const verification = await findOfficialContactEmailVerification({
|
|
19
|
+
organization_id: 42,
|
|
20
|
+
user_id: 42,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
assert.equal(verification, undefined);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("should find the official contact email verification", async () => {
|
|
27
|
+
await pg.sql`
|
|
28
|
+
INSERT INTO organizations
|
|
29
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
30
|
+
VALUES
|
|
31
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
32
|
+
;
|
|
33
|
+
`;
|
|
34
|
+
await pg.sql`
|
|
35
|
+
INSERT INTO users
|
|
36
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
37
|
+
VALUES
|
|
38
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
39
|
+
;
|
|
40
|
+
`;
|
|
41
|
+
await pg.sql`
|
|
42
|
+
INSERT INTO official_contact_email_verifications
|
|
43
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
44
|
+
VALUES
|
|
45
|
+
(1, 1, '666666', '4444-04-04', '4444-04-01', '4444-04-02')
|
|
46
|
+
;
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
const verification = await findOfficialContactEmailVerification({
|
|
50
|
+
organization_id: 1,
|
|
51
|
+
user_id: 1,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
assert.deepEqual(verification, {
|
|
55
|
+
created_at: new Date("4444-04-01"),
|
|
56
|
+
organization_id: 1,
|
|
57
|
+
sent_at: new Date("4444-04-04"),
|
|
58
|
+
token: "666666",
|
|
59
|
+
updated_at: new Date("4444-04-02"),
|
|
60
|
+
user_id: 1,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("should find an official contact email verification without token nor sent_at", async () => {
|
|
65
|
+
await pg.sql`
|
|
66
|
+
INSERT INTO organizations
|
|
67
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
68
|
+
VALUES
|
|
69
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
70
|
+
;
|
|
71
|
+
`;
|
|
72
|
+
await pg.sql`
|
|
73
|
+
INSERT INTO users
|
|
74
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
75
|
+
VALUES
|
|
76
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
77
|
+
;
|
|
78
|
+
`;
|
|
79
|
+
await pg.sql`
|
|
80
|
+
INSERT INTO official_contact_email_verifications
|
|
81
|
+
(user_id, organization_id, created_at, updated_at)
|
|
82
|
+
VALUES
|
|
83
|
+
(1, 1, '4444-04-01', '4444-04-02')
|
|
84
|
+
;
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
const verification = await findOfficialContactEmailVerification({
|
|
88
|
+
organization_id: 1,
|
|
89
|
+
user_id: 1,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
assert.deepEqual(verification, {
|
|
93
|
+
created_at: new Date("4444-04-01"),
|
|
94
|
+
organization_id: 1,
|
|
95
|
+
sent_at: null,
|
|
96
|
+
token: null,
|
|
97
|
+
updated_at: new Date("4444-04-02"),
|
|
98
|
+
user_id: 1,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("should find the verification of the given user and organization only", async () => {
|
|
103
|
+
await pg.sql`
|
|
104
|
+
INSERT INTO organizations
|
|
105
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
106
|
+
VALUES
|
|
107
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19'),
|
|
108
|
+
('Ultramar', 'Ultramarines', 2, '🔵', '1967-12-19', '1967-12-19')
|
|
109
|
+
;
|
|
110
|
+
`;
|
|
111
|
+
await pg.sql`
|
|
112
|
+
INSERT INTO users
|
|
113
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
114
|
+
VALUES
|
|
115
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'),
|
|
116
|
+
(2, 'roboute.guilliman@ultramarines.world', '4444-04-04', '4444-04-04', 'roboute', 'guilliman', 'xiii', 'primarque')
|
|
117
|
+
;
|
|
118
|
+
`;
|
|
119
|
+
await pg.sql`
|
|
120
|
+
INSERT INTO official_contact_email_verifications
|
|
121
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
122
|
+
VALUES
|
|
123
|
+
(1, 1, '111111', '4444-04-04', '4444-04-04', '4444-04-04'),
|
|
124
|
+
(1, 2, '222222', '4444-04-04', '4444-04-04', '4444-04-04'),
|
|
125
|
+
(2, 1, '333333', '4444-04-04', '4444-04-04', '4444-04-04')
|
|
126
|
+
;
|
|
127
|
+
`;
|
|
128
|
+
|
|
129
|
+
const verification = await findOfficialContactEmailVerification({
|
|
130
|
+
organization_id: 2,
|
|
131
|
+
user_id: 1,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
assert.equal(verification?.token, "222222");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DatabaseContext,
|
|
5
|
+
FindOfficialContactEmailVerification,
|
|
6
|
+
OfficialContactEmailVerification,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
import { type QueryResult } from "pg";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export function findOfficialContactEmailVerificationFactory({
|
|
13
|
+
pg,
|
|
14
|
+
}: DatabaseContext) {
|
|
15
|
+
return async function findOfficialContactEmailVerification({
|
|
16
|
+
organization_id,
|
|
17
|
+
user_id,
|
|
18
|
+
}: FindOfficialContactEmailVerification) {
|
|
19
|
+
const { rows }: QueryResult<OfficialContactEmailVerification> =
|
|
20
|
+
await pg.query(
|
|
21
|
+
`
|
|
22
|
+
SELECT *
|
|
23
|
+
FROM official_contact_email_verifications
|
|
24
|
+
WHERE organization_id = $1
|
|
25
|
+
AND user_id = $2;`,
|
|
26
|
+
[organization_id, user_id],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return rows.shift();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { upsertOfficialContactEmailVerificationFactory } from "./upsert-official-contact-email-verification.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const upsertOfficialContactEmailVerification =
|
|
11
|
+
upsertOfficialContactEmailVerificationFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("upsertOfficialContactEmailVerificationFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should insert an official contact email verification", async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO organizations
|
|
20
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
21
|
+
VALUES
|
|
22
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO users
|
|
27
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
28
|
+
VALUES
|
|
29
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const { created_at, updated_at, ...verification } =
|
|
34
|
+
await upsertOfficialContactEmailVerification({
|
|
35
|
+
organization_id: 1,
|
|
36
|
+
sent_at: new Date("4444-04-04"),
|
|
37
|
+
token: "666666",
|
|
38
|
+
user_id: 1,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
assert.deepEqual(verification, {
|
|
42
|
+
organization_id: 1,
|
|
43
|
+
sent_at: new Date("4444-04-04"),
|
|
44
|
+
token: "666666",
|
|
45
|
+
user_id: 1,
|
|
46
|
+
});
|
|
47
|
+
assert.ok(created_at instanceof Date);
|
|
48
|
+
assert.deepEqual(created_at, updated_at);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("should insert an official contact email verification without token nor sent_at", async () => {
|
|
52
|
+
await pg.sql`
|
|
53
|
+
INSERT INTO organizations
|
|
54
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
55
|
+
VALUES
|
|
56
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
57
|
+
;
|
|
58
|
+
`;
|
|
59
|
+
await pg.sql`
|
|
60
|
+
INSERT INTO users
|
|
61
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
62
|
+
VALUES
|
|
63
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
64
|
+
;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const { created_at, updated_at, ...verification } =
|
|
68
|
+
await upsertOfficialContactEmailVerification({
|
|
69
|
+
organization_id: 1,
|
|
70
|
+
sent_at: null,
|
|
71
|
+
token: null,
|
|
72
|
+
user_id: 1,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
assert.deepEqual(verification, {
|
|
76
|
+
organization_id: 1,
|
|
77
|
+
sent_at: null,
|
|
78
|
+
token: null,
|
|
79
|
+
user_id: 1,
|
|
80
|
+
});
|
|
81
|
+
assert.ok(created_at instanceof Date);
|
|
82
|
+
assert.deepEqual(created_at, updated_at);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("should update the existing official contact email verification", async () => {
|
|
86
|
+
await pg.sql`
|
|
87
|
+
INSERT INTO organizations
|
|
88
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
89
|
+
VALUES
|
|
90
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
91
|
+
;
|
|
92
|
+
`;
|
|
93
|
+
await pg.sql`
|
|
94
|
+
INSERT INTO users
|
|
95
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
96
|
+
VALUES
|
|
97
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
98
|
+
;
|
|
99
|
+
`;
|
|
100
|
+
await pg.sql`
|
|
101
|
+
INSERT INTO official_contact_email_verifications
|
|
102
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
103
|
+
VALUES
|
|
104
|
+
(1, 1, '111111', '1967-12-19', '1967-12-19', '1967-12-19')
|
|
105
|
+
;
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const { created_at, updated_at, ...verification } =
|
|
109
|
+
await upsertOfficialContactEmailVerification({
|
|
110
|
+
organization_id: 1,
|
|
111
|
+
sent_at: new Date("4444-04-04"),
|
|
112
|
+
token: "666666",
|
|
113
|
+
user_id: 1,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
assert.deepEqual(verification, {
|
|
117
|
+
organization_id: 1,
|
|
118
|
+
sent_at: new Date("4444-04-04"),
|
|
119
|
+
token: "666666",
|
|
120
|
+
user_id: 1,
|
|
121
|
+
});
|
|
122
|
+
assert.deepEqual(created_at, new Date("1967-12-19"));
|
|
123
|
+
assert.ok(updated_at > new Date("1967-12-19"));
|
|
124
|
+
|
|
125
|
+
const { rows } = await pg.sql`
|
|
126
|
+
SELECT count(*)::int AS count FROM official_contact_email_verifications;
|
|
127
|
+
`;
|
|
128
|
+
assert.deepEqual(rows, [{ count: 1 }]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("❎ fail to insert a verification for an unknown user", async () => {
|
|
132
|
+
await pg.sql`
|
|
133
|
+
INSERT INTO organizations
|
|
134
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
135
|
+
VALUES
|
|
136
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
137
|
+
;
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
await assert.rejects(
|
|
141
|
+
upsertOfficialContactEmailVerification({
|
|
142
|
+
organization_id: 1,
|
|
143
|
+
sent_at: null,
|
|
144
|
+
token: "666666",
|
|
145
|
+
user_id: 42,
|
|
146
|
+
}),
|
|
147
|
+
`error: insert or update on table "official_contact_email_verifications" violates foreign key constraint "official_contact_email_verifications_user_id_fkey"`,
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("❎ fail to insert a verification for an unknown organization", async () => {
|
|
152
|
+
await pg.sql`
|
|
153
|
+
INSERT INTO users
|
|
154
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
155
|
+
VALUES
|
|
156
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
157
|
+
;
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
await assert.rejects(
|
|
161
|
+
upsertOfficialContactEmailVerification({
|
|
162
|
+
organization_id: 42,
|
|
163
|
+
sent_at: null,
|
|
164
|
+
token: "666666",
|
|
165
|
+
user_id: 1,
|
|
166
|
+
}),
|
|
167
|
+
`error: insert or update on table "official_contact_email_verifications" violates foreign key constraint "official_contact_email_verifications_organization_id_fkey"`,
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
BaseOfficialContactEmailVerification,
|
|
5
|
+
DatabaseContext,
|
|
6
|
+
OfficialContactEmailVerification,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
export function upsertOfficialContactEmailVerificationFactory({
|
|
12
|
+
pg,
|
|
13
|
+
}: DatabaseContext) {
|
|
14
|
+
return async function upsertOfficialContactEmailVerification({
|
|
15
|
+
organization_id,
|
|
16
|
+
user_id,
|
|
17
|
+
token,
|
|
18
|
+
sent_at,
|
|
19
|
+
}: BaseOfficialContactEmailVerification) {
|
|
20
|
+
const { rows } = await pg.query<OfficialContactEmailVerification>(
|
|
21
|
+
`
|
|
22
|
+
INSERT INTO official_contact_email_verifications(created_at, updated_at, organization_id, user_id, token, sent_at)
|
|
23
|
+
VALUES (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, $1, $2, $3, $4)
|
|
24
|
+
ON CONFLICT (organization_id, user_id)
|
|
25
|
+
DO UPDATE
|
|
26
|
+
SET organization_id = EXCLUDED.organization_id,
|
|
27
|
+
user_id = EXCLUDED.user_id,
|
|
28
|
+
token = EXCLUDED.token,
|
|
29
|
+
sent_at = EXCLUDED.sent_at,
|
|
30
|
+
updated_at = CURRENT_TIMESTAMP
|
|
31
|
+
RETURNING *
|
|
32
|
+
`,
|
|
33
|
+
[organization_id, user_id, token, sent_at],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return rows.shift()!;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -59,12 +59,11 @@ async function seed() {
|
|
|
59
59
|
|
|
60
60
|
await pg.sql`
|
|
61
61
|
INSERT INTO users_organizations
|
|
62
|
-
|
|
63
|
-
VALUES
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(6, 5, '2023-07-05', '2024-08-15', false, 'imperial', false, 'imperial_token_6', '2023-07-06', true)
|
|
62
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type, has_been_greeted)
|
|
63
|
+
VALUES (1, 1, '2023-01-25', '2024-02-20', false, 'necron', true),
|
|
64
|
+
(1, 3, '2023-04-01', '2024-05-05', true, 'alliance', false),
|
|
65
|
+
(2, 2, '2023-03-01', '2024-04-01', false, 'necron', true),
|
|
66
|
+
(6, 5, '2023-07-05', '2024-08-15', false, 'imperial', true)
|
|
68
67
|
;
|
|
69
68
|
`;
|
|
70
69
|
}
|
|
@@ -24,13 +24,11 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
|
|
|
24
24
|
"organization_info_fetched_at": null,
|
|
25
25
|
"cached_code_officiel_geographique": null,
|
|
26
26
|
"cached_siege_social": null,
|
|
27
|
+
"cached_denomination_usuelle_etablissement_principal": null,
|
|
27
28
|
"is_external": false,
|
|
28
29
|
"verification_type": "necron",
|
|
29
30
|
"verified_at": null,
|
|
30
|
-
"has_been_greeted": true
|
|
31
|
-
"needs_official_contact_email_verification": false,
|
|
32
|
-
"official_contact_email_verification_token": "necron_token_1",
|
|
33
|
-
"official_contact_email_verification_sent_at": "2023-01-26T00:00:00.000Z"
|
|
31
|
+
"has_been_greeted": true
|
|
34
32
|
},
|
|
35
33
|
{
|
|
36
34
|
"id": 3,
|
|
@@ -56,13 +54,11 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
|
|
|
56
54
|
"organization_info_fetched_at": null,
|
|
57
55
|
"cached_code_officiel_geographique": null,
|
|
58
56
|
"cached_siege_social": null,
|
|
57
|
+
"cached_denomination_usuelle_etablissement_principal": null,
|
|
59
58
|
"is_external": true,
|
|
60
59
|
"verification_type": "alliance",
|
|
61
60
|
"verified_at": null,
|
|
62
|
-
"has_been_greeted": false
|
|
63
|
-
"needs_official_contact_email_verification": true,
|
|
64
|
-
"official_contact_email_verification_token": "alliance_token_1",
|
|
65
|
-
"official_contact_email_verification_sent_at": "2023-04-02T00:00:00.000Z"
|
|
61
|
+
"has_been_greeted": false
|
|
66
62
|
}
|
|
67
63
|
]
|
|
68
64
|
`;
|
|
@@ -93,13 +89,11 @@ exports[`findByUserIdFactory > should return single organization when user has o
|
|
|
93
89
|
"organization_info_fetched_at": null,
|
|
94
90
|
"cached_code_officiel_geographique": null,
|
|
95
91
|
"cached_siege_social": null,
|
|
92
|
+
"cached_denomination_usuelle_etablissement_principal": null,
|
|
96
93
|
"is_external": false,
|
|
97
94
|
"verification_type": "imperial",
|
|
98
95
|
"verified_at": null,
|
|
99
|
-
"has_been_greeted": true
|
|
100
|
-
"needs_official_contact_email_verification": false,
|
|
101
|
-
"official_contact_email_verification_token": "imperial_token_6",
|
|
102
|
-
"official_contact_email_verification_sent_at": "2023-07-06T00:00:00.000Z"
|
|
96
|
+
"has_been_greeted": true
|
|
103
97
|
}
|
|
104
98
|
]
|
|
105
99
|
`;
|
|
@@ -14,20 +14,16 @@ export function findByUserIdFactory({ pg }: DatabaseContext) {
|
|
|
14
14
|
const { rows }: QueryResult<Organization & BaseUserOrganizationLink> =
|
|
15
15
|
await pg.query(
|
|
16
16
|
`
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
uo.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
INNER JOIN users_organizations uo ON uo.organization_id = o.id
|
|
28
|
-
WHERE uo.user_id = $1
|
|
29
|
-
ORDER BY o.created_at
|
|
30
|
-
`,
|
|
17
|
+
SELECT o.*,
|
|
18
|
+
uo.is_external,
|
|
19
|
+
uo.verification_type,
|
|
20
|
+
uo.verified_at,
|
|
21
|
+
uo.has_been_greeted
|
|
22
|
+
FROM organizations o
|
|
23
|
+
INNER JOIN users_organizations uo ON uo.organization_id = o.id
|
|
24
|
+
WHERE uo.user_id = $1
|
|
25
|
+
ORDER BY o.created_at
|
|
26
|
+
`,
|
|
31
27
|
[userId],
|
|
32
28
|
);
|
|
33
29
|
|
package/src/repositories/organization/{find-by-id.test.ts → find-organization-by-id.test.ts}
RENAMED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { findOrganizationByIdFactory } from "./find-organization-by-id.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const findOrganizationById = findOrganizationByIdFactory({ pg: pg as any });
|
|
11
11
|
|
|
12
|
-
suite("
|
|
12
|
+
suite("findOrganizationByIdFactory", () => {
|
|
13
13
|
before(migrate);
|
|
14
14
|
beforeEach(emptyDatabase);
|
|
15
15
|
|
|
@@ -21,7 +21,7 @@ suite("findByIdFactory", () => {
|
|
|
21
21
|
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
22
22
|
;
|
|
23
23
|
`;
|
|
24
|
-
const organization = await
|
|
24
|
+
const organization = await findOrganizationById(1);
|
|
25
25
|
|
|
26
26
|
assert.deepEqual(organization, {
|
|
27
27
|
cached_activite_principale: null,
|
|
@@ -42,6 +42,7 @@ suite("findByIdFactory", () => {
|
|
|
42
42
|
cached_statut_diffusion: null,
|
|
43
43
|
cached_tranche_effectifs_unite_legale: null,
|
|
44
44
|
cached_tranche_effectifs: null,
|
|
45
|
+
cached_denomination_usuelle_etablissement_principal: null,
|
|
45
46
|
created_at: new Date("1967-12-19"),
|
|
46
47
|
organization_info_fetched_at: null,
|
|
47
48
|
id: 1,
|
|
@@ -5,8 +5,8 @@ import type { QueryResult } from "pg";
|
|
|
5
5
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
export function
|
|
9
|
-
return async function
|
|
8
|
+
export function findOrganizationByIdFactory({ pg }: DatabaseContext) {
|
|
9
|
+
return async function findOrganizationById(id: number) {
|
|
10
10
|
const { rows }: QueryResult<Organization> = await pg.query(
|
|
11
11
|
`
|
|
12
12
|
SELECT *
|
|
@@ -19,4 +19,4 @@ export function findByIdFactory({ pg }: DatabaseContext) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export type FindByIdHandler = ReturnType<typeof
|
|
22
|
+
export type FindByIdHandler = ReturnType<typeof findOrganizationByIdFactory>;
|