@proconnect-gouv/proconnect.identite 1.6.2 → 1.7.1
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 +12 -0
- package/dist/managers/organization/index.d.ts +0 -1
- package/dist/managers/organization/index.d.ts.map +1 -1
- package/dist/managers/organization/index.js +0 -1
- package/dist/managers/organization/mark-domain-as-verified.d.ts +12 -3
- package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
- package/dist/managers/organization/mark-domain-as-verified.js +7 -7
- package/dist/repositories/email-domain/add-domain.d.ts +12 -3
- package/dist/repositories/email-domain/add-domain.d.ts.map +1 -1
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts +2 -2
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts.map +1 -1
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.js +1 -3
- package/dist/repositories/email-domain/find-email-domains-by-organization-id.d.ts +11 -2
- package/dist/repositories/email-domain/find-email-domains-by-organization-id.d.ts.map +1 -1
- package/dist/repositories/organization/find-by-user-id.d.ts +1 -1
- package/dist/repositories/organization/get-users-by-organization.d.ts +1 -1
- package/dist/repositories/organization/index.d.ts +0 -1
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +0 -1
- package/dist/repositories/organization/link-user-to-organization.d.ts +1 -1
- package/dist/repositories/user/update-user-organization-link.d.ts +1 -1
- package/dist/services/organization/is-public-service.d.ts +1 -1
- package/dist/services/organization/is-public-service.d.ts.map +1 -1
- package/dist/types/email-domain.d.ts +37 -16
- package/dist/types/email-domain.d.ts.map +1 -1
- package/dist/types/email-domain.js +30 -7
- package/dist/types/user-organization-link.d.ts +7 -6
- package/dist/types/user-organization-link.d.ts.map +1 -1
- package/dist/types/user-organization-link.js +2 -2
- package/package.json +1 -1
- package/src/managers/organization/index.ts +0 -1
- package/src/managers/organization/mark-domain-as-verified.test.ts.snapshot +2 -1
- package/src/managers/organization/mark-domain-as-verified.ts +16 -17
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +97 -0
- package/src/repositories/email-domain/add-domain.ts +6 -2
- package/src/repositories/email-domain/delete-email-domains-by-verification-types.test.ts +2 -2
- package/src/repositories/email-domain/delete-email-domains-by-verification-types.ts +7 -7
- package/src/repositories/email-domain/find-email-domains-by-organization-id.test.ts +3 -3
- package/src/repositories/organization/index.ts +0 -1
- package/src/services/organization/is-public-service.ts +4 -1
- package/src/types/email-domain.ts +44 -27
- package/src/types/user-organization-link.ts +4 -2
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/managers/organization/force-join-organization.d.ts +0 -29
- package/dist/managers/organization/force-join-organization.d.ts.map +0 -1
- package/dist/managers/organization/force-join-organization.js +0 -32
- package/dist/repositories/organization/get-by-id.d.ts +0 -4
- package/dist/repositories/organization/get-by-id.d.ts.map +0 -1
- package/dist/repositories/organization/get-by-id.js +0 -15
- package/src/managers/organization/force-join-organization.test.ts +0 -94
- package/src/managers/organization/force-join-organization.ts +0 -87
- package/src/repositories/organization/get-by-id.test.ts +0 -61
- package/src/repositories/organization/get-by-id.ts +0 -21
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { FindEmailDomainsByOrganizationIdHandler } from "#src/repositories/email-domain";
|
|
2
|
-
import type { GetByIdHandler as GetOrganizationByIdHandler, LinkUserToOrganizationHandler } from "#src/repositories/organization";
|
|
3
|
-
import type { GetByIdHandler as GetUserByIdHandler } from "#src/repositories/user";
|
|
4
|
-
type FactoryDependencies = {
|
|
5
|
-
findEmailDomainsByOrganizationId: FindEmailDomainsByOrganizationIdHandler;
|
|
6
|
-
getById: GetOrganizationByIdHandler;
|
|
7
|
-
getUserById: GetUserByIdHandler;
|
|
8
|
-
linkUserToOrganization: LinkUserToOrganizationHandler;
|
|
9
|
-
};
|
|
10
|
-
export declare function forceJoinOrganizationFactory({ findEmailDomainsByOrganizationId, getById, getUserById, linkUserToOrganization, }: FactoryDependencies): ({ organization_id, user_id, is_external, }: {
|
|
11
|
-
organization_id: number;
|
|
12
|
-
user_id: number;
|
|
13
|
-
is_external?: boolean;
|
|
14
|
-
}) => Promise<{
|
|
15
|
-
is_external: boolean;
|
|
16
|
-
verification_type: "organization_dirigeant" | "code_sent_to_official_contact_email" | "domain" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
|
|
17
|
-
verified_at: Date | null;
|
|
18
|
-
has_been_greeted: boolean;
|
|
19
|
-
needs_official_contact_email_verification: boolean;
|
|
20
|
-
official_contact_email_verification_token: string | null;
|
|
21
|
-
official_contact_email_verification_sent_at: Date | null;
|
|
22
|
-
user_id: number;
|
|
23
|
-
organization_id: number;
|
|
24
|
-
created_at: Date;
|
|
25
|
-
updated_at: Date;
|
|
26
|
-
}>;
|
|
27
|
-
export type ForceJoinOrganizationHandler = ReturnType<typeof forceJoinOrganizationFactory>;
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=force-join-organization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"force-join-organization.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/force-join-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,gCAAgC,CAAC;AAC9F,OAAO,KAAK,EACV,cAAc,IAAI,0BAA0B,EAC5C,6BAA6B,EAC9B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAOnF,KAAK,mBAAmB,GAAG;IACzB,gCAAgC,EAAE,uCAAuC,CAAC;IAC1E,OAAO,EAAE,0BAA0B,CAAC;IACpC,WAAW,EAAE,kBAAkB,CAAC;IAChC,sBAAsB,EAAE,6BAA6B,CAAC;CACvD,CAAC;AAIF,wBAAgB,4BAA4B,CAAC,EAC3C,gCAAgC,EAChC,OAAO,EACP,WAAW,EACX,sBAAsB,GACvB,EAAE,mBAAmB,IACwB,4CAIzC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;;;;;;;;;;;;GA6CF;AAED,MAAM,MAAM,4BAA4B,GAAG,UAAU,CACnD,OAAO,4BAA4B,CACpC,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { LinkTypes } from "#src/types";
|
|
3
|
-
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
4
|
-
import { match } from "ts-pattern";
|
|
5
|
-
//
|
|
6
|
-
export function forceJoinOrganizationFactory({ findEmailDomainsByOrganizationId, getById, getUserById, linkUserToOrganization, }) {
|
|
7
|
-
return async function forceJoinOrganization({ organization_id, user_id, is_external = false, }) {
|
|
8
|
-
const user = await getUserById(user_id);
|
|
9
|
-
// Ensure that the organization exists (Ceinture Bretelle)
|
|
10
|
-
await getById(organization_id);
|
|
11
|
-
const { email } = user;
|
|
12
|
-
const domain = getEmailDomain(email);
|
|
13
|
-
const organizationEmailDomains = await findEmailDomainsByOrganizationId(organization_id);
|
|
14
|
-
const link_verification_type = organizationEmailDomains
|
|
15
|
-
.filter(({ domain: currentDomain }) => currentDomain === domain)
|
|
16
|
-
.reduce((acc, { verification_type }) => {
|
|
17
|
-
if (acc === "domain") {
|
|
18
|
-
return acc;
|
|
19
|
-
}
|
|
20
|
-
return match(verification_type)
|
|
21
|
-
.with("verified", "trackdechets_postal_mail", "external", "official_contact", () => LinkTypes.enum.domain)
|
|
22
|
-
.with(null, "blacklisted", "refused", () => LinkTypes.enum.no_validation_means_available)
|
|
23
|
-
.exhaustive();
|
|
24
|
-
}, "no_validation_means_available");
|
|
25
|
-
return await linkUserToOrganization({
|
|
26
|
-
organization_id,
|
|
27
|
-
user_id,
|
|
28
|
-
is_external,
|
|
29
|
-
verification_type: link_verification_type,
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { DatabaseContext } from "#src/types";
|
|
2
|
-
export declare function getByIdFactory({ pg }: DatabaseContext): (id: number) => Promise<import("#src/types").Organization>;
|
|
3
|
-
export type GetByIdHandler = ReturnType<typeof getByIdFactory>;
|
|
4
|
-
//# sourceMappingURL=get-by-id.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-by-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/get-by-id.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAMlD,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAEtB,IAAI,MAAM,gDAOzC;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { OrganizationNotFoundError } from "#src/errors";
|
|
3
|
-
import { isEmpty } from "lodash-es";
|
|
4
|
-
import { findByIdFactory } from "./find-by-id.js";
|
|
5
|
-
//
|
|
6
|
-
export function getByIdFactory({ pg }) {
|
|
7
|
-
const findById = findByIdFactory({ pg });
|
|
8
|
-
return async function getById(id) {
|
|
9
|
-
const organization = await findById(id);
|
|
10
|
-
if (isEmpty(organization)) {
|
|
11
|
-
throw new OrganizationNotFoundError("Organization not found");
|
|
12
|
-
}
|
|
13
|
-
return organization;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { NotFoundError } from "#src/errors";
|
|
2
|
-
import type { Organization, User } from "#src/types";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
import { suite, test } from "node:test";
|
|
5
|
-
import type { EmailDomain } from "../../types/index.js";
|
|
6
|
-
import { forceJoinOrganizationFactory } from "./force-join-organization.js";
|
|
7
|
-
|
|
8
|
-
suite("forceJoinOrganizationFactory", () => {
|
|
9
|
-
test("should update the organization user link ", async () => {
|
|
10
|
-
const forceJoinOrganization = forceJoinOrganizationFactory({
|
|
11
|
-
findEmailDomainsByOrganizationId: () => Promise.resolve([]),
|
|
12
|
-
getById: () => Promise.resolve({ id: 42 } as Organization),
|
|
13
|
-
getUserById: () =>
|
|
14
|
-
Promise.resolve({ email: "lion.eljonson@darkangels.world" } as User),
|
|
15
|
-
linkUserToOrganization: (values) => Promise.resolve(values as any),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
assert.deepEqual(
|
|
19
|
-
await forceJoinOrganization({
|
|
20
|
-
organization_id: 42,
|
|
21
|
-
user_id: 42,
|
|
22
|
-
}),
|
|
23
|
-
{
|
|
24
|
-
is_external: false,
|
|
25
|
-
organization_id: 42,
|
|
26
|
-
user_id: 42,
|
|
27
|
-
verification_type: "no_validation_means_available",
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("should update the organization user link with domain verification ", async () => {
|
|
33
|
-
const forceJoinOrganization = forceJoinOrganizationFactory({
|
|
34
|
-
findEmailDomainsByOrganizationId: () =>
|
|
35
|
-
Promise.resolve([
|
|
36
|
-
{
|
|
37
|
-
domain: "darkangels.world",
|
|
38
|
-
verification_type: "verified",
|
|
39
|
-
} as EmailDomain,
|
|
40
|
-
]),
|
|
41
|
-
getById: () => Promise.resolve({ id: 42 } as Organization),
|
|
42
|
-
getUserById: () =>
|
|
43
|
-
Promise.resolve({ email: "lion.eljonson@darkangels.world" } as User),
|
|
44
|
-
linkUserToOrganization: (values) => Promise.resolve(values as any),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
assert.deepEqual(
|
|
48
|
-
await forceJoinOrganization({
|
|
49
|
-
organization_id: 42,
|
|
50
|
-
user_id: 42,
|
|
51
|
-
}),
|
|
52
|
-
{
|
|
53
|
-
is_external: false,
|
|
54
|
-
organization_id: 42,
|
|
55
|
-
user_id: 42,
|
|
56
|
-
verification_type: "domain",
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("❎ throws NotFoundError for unknown organization", async () => {
|
|
62
|
-
const forceJoinOrganization = forceJoinOrganizationFactory({
|
|
63
|
-
findEmailDomainsByOrganizationId: () => Promise.resolve([]),
|
|
64
|
-
getById: () => Promise.reject(new NotFoundError("💣")),
|
|
65
|
-
getUserById: () => Promise.resolve({ id: 42 } as User),
|
|
66
|
-
linkUserToOrganization: () => Promise.reject(),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
await assert.rejects(
|
|
70
|
-
forceJoinOrganization({
|
|
71
|
-
organization_id: 42,
|
|
72
|
-
user_id: 42,
|
|
73
|
-
}),
|
|
74
|
-
new NotFoundError("💣"),
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("❎ throws NotFoundError for unknown user", async () => {
|
|
79
|
-
const forceJoinOrganization = forceJoinOrganizationFactory({
|
|
80
|
-
findEmailDomainsByOrganizationId: () => Promise.resolve([]),
|
|
81
|
-
getById: () => Promise.resolve({ id: 42 } as Organization),
|
|
82
|
-
getUserById: () => Promise.reject(new NotFoundError("💣")),
|
|
83
|
-
linkUserToOrganization: () => Promise.reject(),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
await assert.rejects(
|
|
87
|
-
forceJoinOrganization({
|
|
88
|
-
organization_id: 42,
|
|
89
|
-
user_id: 42,
|
|
90
|
-
}),
|
|
91
|
-
new NotFoundError("💣"),
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { FindEmailDomainsByOrganizationIdHandler } from "#src/repositories/email-domain";
|
|
4
|
-
import type {
|
|
5
|
-
GetByIdHandler as GetOrganizationByIdHandler,
|
|
6
|
-
LinkUserToOrganizationHandler,
|
|
7
|
-
} from "#src/repositories/organization";
|
|
8
|
-
import type { GetByIdHandler as GetUserByIdHandler } from "#src/repositories/user";
|
|
9
|
-
import { type BaseUserOrganizationLink, LinkTypes } from "#src/types";
|
|
10
|
-
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
11
|
-
import { match } from "ts-pattern";
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
type FactoryDependencies = {
|
|
16
|
-
findEmailDomainsByOrganizationId: FindEmailDomainsByOrganizationIdHandler;
|
|
17
|
-
getById: GetOrganizationByIdHandler;
|
|
18
|
-
getUserById: GetUserByIdHandler;
|
|
19
|
-
linkUserToOrganization: LinkUserToOrganizationHandler;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
export function forceJoinOrganizationFactory({
|
|
25
|
-
findEmailDomainsByOrganizationId,
|
|
26
|
-
getById,
|
|
27
|
-
getUserById,
|
|
28
|
-
linkUserToOrganization,
|
|
29
|
-
}: FactoryDependencies) {
|
|
30
|
-
return async function forceJoinOrganization({
|
|
31
|
-
organization_id,
|
|
32
|
-
user_id,
|
|
33
|
-
is_external = false,
|
|
34
|
-
}: {
|
|
35
|
-
organization_id: number;
|
|
36
|
-
user_id: number;
|
|
37
|
-
is_external?: boolean;
|
|
38
|
-
}) {
|
|
39
|
-
const user = await getUserById(user_id);
|
|
40
|
-
|
|
41
|
-
// Ensure that the organization exists (Ceinture Bretelle)
|
|
42
|
-
await getById(organization_id);
|
|
43
|
-
|
|
44
|
-
const { email } = user;
|
|
45
|
-
const domain = getEmailDomain(email);
|
|
46
|
-
const organizationEmailDomains =
|
|
47
|
-
await findEmailDomainsByOrganizationId(organization_id);
|
|
48
|
-
|
|
49
|
-
const link_verification_type = organizationEmailDomains
|
|
50
|
-
.filter(({ domain: currentDomain }) => currentDomain === domain)
|
|
51
|
-
.reduce(
|
|
52
|
-
(acc, { verification_type }) => {
|
|
53
|
-
if (acc === "domain") {
|
|
54
|
-
return acc;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return match(verification_type)
|
|
58
|
-
.with(
|
|
59
|
-
"verified",
|
|
60
|
-
"trackdechets_postal_mail",
|
|
61
|
-
"external",
|
|
62
|
-
"official_contact",
|
|
63
|
-
() => LinkTypes.enum.domain,
|
|
64
|
-
)
|
|
65
|
-
.with(
|
|
66
|
-
null,
|
|
67
|
-
"blacklisted",
|
|
68
|
-
"refused",
|
|
69
|
-
() => LinkTypes.enum.no_validation_means_available,
|
|
70
|
-
)
|
|
71
|
-
.exhaustive();
|
|
72
|
-
},
|
|
73
|
-
"no_validation_means_available" as BaseUserOrganizationLink["verification_type"],
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
return await linkUserToOrganization({
|
|
77
|
-
organization_id,
|
|
78
|
-
user_id,
|
|
79
|
-
is_external,
|
|
80
|
-
verification_type: link_verification_type,
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export type ForceJoinOrganizationHandler = ReturnType<
|
|
86
|
-
typeof forceJoinOrganizationFactory
|
|
87
|
-
>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { OrganizationNotFoundError } from "#src/errors";
|
|
4
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
5
|
-
import assert from "node:assert/strict";
|
|
6
|
-
import { before, beforeEach, suite, test } from "node:test";
|
|
7
|
-
import { getByIdFactory } from "./get-by-id.js";
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
const getById = getByIdFactory({ pg: pg as any });
|
|
12
|
-
|
|
13
|
-
suite("getByIdFactory", () => {
|
|
14
|
-
before(migrate);
|
|
15
|
-
beforeEach(emptyDatabase);
|
|
16
|
-
|
|
17
|
-
test("should find a user by id", 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
|
-
|
|
26
|
-
const organization = await getById(1);
|
|
27
|
-
|
|
28
|
-
assert.deepEqual(organization, {
|
|
29
|
-
cached_activite_principale: null,
|
|
30
|
-
cached_adresse: null,
|
|
31
|
-
cached_categorie_juridique: null,
|
|
32
|
-
cached_code_officiel_geographique: null,
|
|
33
|
-
cached_code_postal: null,
|
|
34
|
-
cached_enseigne: null,
|
|
35
|
-
cached_est_active: null,
|
|
36
|
-
cached_est_diffusible: null,
|
|
37
|
-
cached_etat_administratif: null,
|
|
38
|
-
cached_libelle_activite_principale: null,
|
|
39
|
-
cached_libelle_categorie_juridique: null,
|
|
40
|
-
cached_libelle_tranche_effectif: null,
|
|
41
|
-
cached_libelle: "Necron",
|
|
42
|
-
cached_nom_complet: "Necrontyr",
|
|
43
|
-
cached_siege_social: null,
|
|
44
|
-
cached_statut_diffusion: null,
|
|
45
|
-
cached_tranche_effectifs_unite_legale: null,
|
|
46
|
-
cached_tranche_effectifs: null,
|
|
47
|
-
created_at: new Date("1967-12-19"),
|
|
48
|
-
organization_info_fetched_at: null,
|
|
49
|
-
id: 1,
|
|
50
|
-
siret: "⚰️",
|
|
51
|
-
updated_at: new Date("1967-12-19"),
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("❎ fail to find the God-Emperor of Mankind", async () => {
|
|
56
|
-
await assert.rejects(
|
|
57
|
-
getById(42),
|
|
58
|
-
new OrganizationNotFoundError("Organization not found"),
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { OrganizationNotFoundError } from "#src/errors";
|
|
4
|
-
import type { DatabaseContext } from "#src/types";
|
|
5
|
-
import { isEmpty } from "lodash-es";
|
|
6
|
-
import { findByIdFactory } from "./find-by-id.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
export function getByIdFactory({ pg }: DatabaseContext) {
|
|
11
|
-
const findById = findByIdFactory({ pg });
|
|
12
|
-
return async function getById(id: number) {
|
|
13
|
-
const organization = await findById(id);
|
|
14
|
-
if (isEmpty(organization)) {
|
|
15
|
-
throw new OrganizationNotFoundError("Organization not found");
|
|
16
|
-
}
|
|
17
|
-
return organization;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type GetByIdHandler = ReturnType<typeof getByIdFactory>;
|