@proconnect-gouv/proconnect.identite 16.0.0 → 17.0.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 +0 -71
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +4 -14
- package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
- package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
- package/dist/repositories/authenticator/index.d.ts +0 -1
- package/dist/repositories/authenticator/index.d.ts.map +1 -1
- package/dist/repositories/authenticator/index.js +0 -1
- package/dist/repositories/moderation/index.d.ts +0 -2
- package/dist/repositories/moderation/index.d.ts.map +1 -1
- package/dist/repositories/moderation/index.js +0 -2
- package/dist/repositories/organization/index.d.ts +0 -2
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +0 -2
- package/dist/repositories/user/index.d.ts +0 -1
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +0 -1
- package/dist/types/authenticator.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/connectors/index.ts +0 -17
- package/src/managers/certification/process-certification-dirigeant.ts +1 -2
- package/src/managers/organization/get-organization-info.ts +1 -2
- package/src/repositories/authenticator/index.ts +0 -1
- package/src/repositories/moderation/index.ts +0 -2
- package/src/repositories/organization/index.ts +0 -2
- package/src/repositories/user/index.ts +0 -1
- package/src/types/authenticator.ts +1 -7
- package/testing/index.ts +2 -1
- package/dist/repositories/authenticator/update-authenticator.d.ts +0 -3
- package/dist/repositories/authenticator/update-authenticator.d.ts.map +0 -1
- package/dist/repositories/authenticator/update-authenticator.js +0 -13
- package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.d.ts +0 -3
- package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.d.ts.map +0 -1
- package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.js +0 -15
- package/dist/repositories/email-deliverability-whitelist/index.d.ts +0 -2
- package/dist/repositories/email-deliverability-whitelist/index.d.ts.map +0 -1
- package/dist/repositories/email-deliverability-whitelist/index.js +0 -2
- package/dist/repositories/moderation/find-pending-moderation.d.ts +0 -20
- package/dist/repositories/moderation/find-pending-moderation.d.ts.map +0 -1
- package/dist/repositories/moderation/find-pending-moderation.js +0 -16
- package/dist/repositories/moderation/find-rejected-moderation.d.ts +0 -20
- package/dist/repositories/moderation/find-rejected-moderation.d.ts.map +0 -1
- package/dist/repositories/moderation/find-rejected-moderation.js +0 -17
- package/dist/repositories/organization/find-by-siret.d.ts +0 -3
- package/dist/repositories/organization/find-by-siret.d.ts.map +0 -1
- package/dist/repositories/organization/find-by-siret.js +0 -13
- package/dist/repositories/organization/find-pending-by-user-id.d.ts +0 -6
- package/dist/repositories/organization/find-pending-by-user-id.d.ts.map +0 -1
- package/dist/repositories/organization/find-pending-by-user-id.js +0 -18
- package/dist/repositories/user/find-by-reset-password-token.d.ts +0 -29
- package/dist/repositories/user/find-by-reset-password-token.d.ts.map +0 -1
- package/dist/repositories/user/find-by-reset-password-token.js +0 -12
- package/src/repositories/authenticator/update-authenticator.test.ts +0 -41
- package/src/repositories/authenticator/update-authenticator.ts +0 -29
- package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.test.ts +0 -45
- package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.ts +0 -24
- package/src/repositories/email-deliverability-whitelist/index.ts +0 -3
- package/src/repositories/moderation/find-pending-moderation.test.ts +0 -57
- package/src/repositories/moderation/find-pending-moderation.ts +0 -35
- package/src/repositories/moderation/find-rejected-moderation.test.ts +0 -57
- package/src/repositories/moderation/find-rejected-moderation.ts +0 -37
- package/src/repositories/organization/find-by-siret.test.ts +0 -35
- package/src/repositories/organization/find-by-siret.ts +0 -21
- package/src/repositories/organization/find-pending-by-user-id.test.ts +0 -51
- package/src/repositories/organization/find-pending-by-user-id.ts +0 -27
- package/src/repositories/user/find-by-reset-password-token.test.ts +0 -37
- package/src/repositories/user/find-by-reset-password-token.ts +0 -20
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type DatabaseContext, type ModerationType } from "#src/types";
|
|
2
|
-
export declare function findRejectedModerationFactory({ pg }: DatabaseContext): ({ user_id, organization_id, type, }: {
|
|
3
|
-
user_id: number;
|
|
4
|
-
organization_id: number;
|
|
5
|
-
type: ModerationType;
|
|
6
|
-
}) => Promise<{
|
|
7
|
-
id: number;
|
|
8
|
-
user_id: number;
|
|
9
|
-
organization_id: number;
|
|
10
|
-
ticket_id: string | null;
|
|
11
|
-
type: "non_verified_domain" | "organization_join_block";
|
|
12
|
-
created_at: Date;
|
|
13
|
-
moderated_at: Date | null;
|
|
14
|
-
comment: string | null;
|
|
15
|
-
moderated_by: string | null;
|
|
16
|
-
status: "accepted" | "pending" | "rejected" | "reopened" | "unknown";
|
|
17
|
-
end_user_reason: string;
|
|
18
|
-
allow_editing: boolean;
|
|
19
|
-
} | undefined>;
|
|
20
|
-
//# sourceMappingURL=find-rejected-moderation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-rejected-moderation.d.ts","sourceRoot":"","sources":["../../../src/repositories/moderation/find-rejected-moderation.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,qCAI1C;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,cAAc,CAAC;CACtB;;;;;;;;;;;;;eAeF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { ModerationStatusSchema, } from "#src/types";
|
|
3
|
-
import {} from "pg";
|
|
4
|
-
//
|
|
5
|
-
export function findRejectedModerationFactory({ pg }) {
|
|
6
|
-
return async function findRejectedModeration({ user_id, organization_id, type, }) {
|
|
7
|
-
const { rows } = await pg.query(`
|
|
8
|
-
SELECT *
|
|
9
|
-
FROM moderations
|
|
10
|
-
WHERE user_id = $1
|
|
11
|
-
AND organization_id = $2
|
|
12
|
-
AND type = $3
|
|
13
|
-
AND moderated_at IS NOT NULL
|
|
14
|
-
AND status = $4;`, [user_id, organization_id, type, ModerationStatusSchema.enum.rejected]);
|
|
15
|
-
return rows.shift();
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-by-siret.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-by-siret.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAKhE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,OAAO,MAAM,uCAYhD"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {} from "pg";
|
|
3
|
-
//
|
|
4
|
-
export function findBySiretFactory({ pg }) {
|
|
5
|
-
return async function findBySiret(siret) {
|
|
6
|
-
const { rows } = await pg.query(`
|
|
7
|
-
SELECT *
|
|
8
|
-
FROM organizations
|
|
9
|
-
WHERE siret = $1
|
|
10
|
-
`, [siret]);
|
|
11
|
-
return rows.shift();
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { DatabaseContext } from "#src/types";
|
|
2
|
-
import { type Organization } from "#src/types";
|
|
3
|
-
export declare function findPendingByUserIdFactory({ pg }: DatabaseContext): (user_id: number) => Promise<(Organization & {
|
|
4
|
-
moderation_id: number;
|
|
5
|
-
})[]>;
|
|
6
|
-
//# sourceMappingURL=find-pending-by-user-id.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-pending-by-user-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-pending-by-user-id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAKrE,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,SAAS,MAAM;mBACK,MAAM;MAgBrE"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { ModerationTypeSchema } from "#src/types";
|
|
3
|
-
import {} from "pg";
|
|
4
|
-
//
|
|
5
|
-
export function findPendingByUserIdFactory({ pg }) {
|
|
6
|
-
return async function findPendingByUserId(user_id) {
|
|
7
|
-
const { rows } = await pg.query(`
|
|
8
|
-
SELECT o.*, m.id as moderation_id
|
|
9
|
-
FROM moderations m
|
|
10
|
-
INNER JOIN organizations o on o.id = m.organization_id
|
|
11
|
-
WHERE m.user_id = $1
|
|
12
|
-
AND m.type = $2
|
|
13
|
-
AND m.moderated_at IS NULL
|
|
14
|
-
ORDER BY m.created_at
|
|
15
|
-
`, [user_id, ModerationTypeSchema.enum.organization_join_block]);
|
|
16
|
-
return rows;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { DatabaseContext } from "#src/types";
|
|
2
|
-
export declare function findByResetPasswordTokenFactory({ pg }: DatabaseContext): (reset_password_token: string) => Promise<{
|
|
3
|
-
created_at: Date;
|
|
4
|
-
current_challenge: string | null;
|
|
5
|
-
email: string;
|
|
6
|
-
email_verified: boolean;
|
|
7
|
-
email_verified_at: Date | null;
|
|
8
|
-
encrypted_password: string | null;
|
|
9
|
-
encrypted_totp_key: string | null;
|
|
10
|
-
family_name: string | null;
|
|
11
|
-
force_2fa: boolean;
|
|
12
|
-
given_name: string | null;
|
|
13
|
-
id: number;
|
|
14
|
-
job: string | null;
|
|
15
|
-
last_sign_in_at: Date | null;
|
|
16
|
-
magic_link_sent_at: Date | null;
|
|
17
|
-
magic_link_token: string | null;
|
|
18
|
-
needs_inclusionconnect_onboarding_help: boolean;
|
|
19
|
-
needs_inclusionconnect_welcome_page: boolean;
|
|
20
|
-
phone_number: string | null;
|
|
21
|
-
reset_password_sent_at: Date | null;
|
|
22
|
-
reset_password_token: string | null;
|
|
23
|
-
sign_in_count: number;
|
|
24
|
-
totp_key_verified_at: Date | null;
|
|
25
|
-
updated_at: Date;
|
|
26
|
-
verify_email_sent_at: Date | null;
|
|
27
|
-
verify_email_token: string | null;
|
|
28
|
-
} | undefined>;
|
|
29
|
-
//# sourceMappingURL=find-by-reset-password-token.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-by-reset-password-token.d.ts","sourceRoot":"","sources":["../../../src/repositories/user/find-by-reset-password-token.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAQ,MAAM,YAAY,CAAC;AAKxD,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,sBAAsB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;eAW5E"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {} from "pg";
|
|
3
|
-
//
|
|
4
|
-
export function findByResetPasswordTokenFactory({ pg }) {
|
|
5
|
-
return async function findByResetPasswordToken(reset_password_token) {
|
|
6
|
-
const { rows } = await pg.query(`
|
|
7
|
-
SELECT *
|
|
8
|
-
FROM users WHERE reset_password_token = $1
|
|
9
|
-
`, [reset_password_token]);
|
|
10
|
-
return rows.shift();
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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 { updateAuthenticatorFactory } from "./update-authenticator.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const updateAuthenticator = updateAuthenticatorFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("updateAuthenticatorFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should update and return the authenticator", async () => {
|
|
17
|
-
await pg.sql`
|
|
18
|
-
INSERT INTO users
|
|
19
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
20
|
-
VALUES
|
|
21
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
22
|
-
;
|
|
23
|
-
`;
|
|
24
|
-
await pg.sql`
|
|
25
|
-
INSERT INTO authenticators
|
|
26
|
-
(credential_id, credential_public_key, counter, credential_backed_up, user_id, usage_count, user_verified, last_used_at)
|
|
27
|
-
VALUES
|
|
28
|
-
('CRED1', '\\x00', 0, false, 1, 0, true, '4444-04-04')
|
|
29
|
-
;
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
const result = await updateAuthenticator("CRED1", {
|
|
33
|
-
counter: 7,
|
|
34
|
-
last_used_at: new Date("4444-04-05"),
|
|
35
|
-
usage_count: 3,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
assert.equal(result.counter, 7);
|
|
39
|
-
assert.equal(result.usage_count, 3);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
Authenticator,
|
|
5
|
-
Base64URLString,
|
|
6
|
-
BaseAuthenticator,
|
|
7
|
-
DatabaseContext,
|
|
8
|
-
} from "#src/types";
|
|
9
|
-
import { type QueryResult } from "pg";
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
export function updateAuthenticatorFactory({ pg }: DatabaseContext) {
|
|
14
|
-
return async function updateAuthenticator(
|
|
15
|
-
credential_id: Base64URLString,
|
|
16
|
-
{ counter, last_used_at, usage_count }: Partial<BaseAuthenticator>,
|
|
17
|
-
) {
|
|
18
|
-
const { rows }: QueryResult<Authenticator> = await pg.query(
|
|
19
|
-
`
|
|
20
|
-
UPDATE authenticators
|
|
21
|
-
SET counter = $2, last_used_at = $3, usage_count = $4
|
|
22
|
-
WHERE credential_id = $1
|
|
23
|
-
RETURNING *`,
|
|
24
|
-
[credential_id, counter, last_used_at, usage_count],
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return rows.shift()!;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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 { findEmailInDeliverabilityWhiteListFactory } from "./find-email-in-deliverability-white-list.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findEmailInDeliverabilityWhiteList =
|
|
11
|
-
findEmailInDeliverabilityWhiteListFactory({ pg: pg as any });
|
|
12
|
-
|
|
13
|
-
suite("findEmailInDeliverabilityWhiteListFactory", () => {
|
|
14
|
-
before(migrate);
|
|
15
|
-
beforeEach(emptyDatabase);
|
|
16
|
-
|
|
17
|
-
test("should return undefined when the domain is not whitelisted", async () => {
|
|
18
|
-
const result = await findEmailInDeliverabilityWhiteList(
|
|
19
|
-
"lion@darkangels.world",
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
assert.equal(result, undefined);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("should return the whitelist entry when the domain matches", async () => {
|
|
26
|
-
await pg.sql`
|
|
27
|
-
INSERT INTO email_deliverability_whitelist
|
|
28
|
-
(problematic_email, email_domain)
|
|
29
|
-
VALUES
|
|
30
|
-
('lion@darkangels.world', 'darkangels.world')
|
|
31
|
-
;
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
const result = await findEmailInDeliverabilityWhiteList(
|
|
35
|
-
"lion@darkangels.world",
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
assert.deepEqual(result, {
|
|
39
|
-
problematic_email: "lion@darkangels.world",
|
|
40
|
-
email_domain: "darkangels.world",
|
|
41
|
-
verified_at: result?.verified_at,
|
|
42
|
-
verified_by: null,
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { type DatabaseContext } from "#src/types";
|
|
4
|
-
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
5
|
-
import { type QueryResult } from "pg";
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
export function findEmailInDeliverabilityWhiteListFactory({
|
|
10
|
-
pg,
|
|
11
|
-
}: DatabaseContext) {
|
|
12
|
-
return async function findEmailInDeliverabilityWhiteList(email: string) {
|
|
13
|
-
const domain = getEmailDomain(email);
|
|
14
|
-
const { rows }: QueryResult<{}> = await pg.query(
|
|
15
|
-
`
|
|
16
|
-
SELECT *
|
|
17
|
-
FROM email_deliverability_whitelist WHERE email_domain = $1
|
|
18
|
-
`,
|
|
19
|
-
[domain],
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
return rows.shift();
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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 { findPendingModerationFactory } from "./find-pending-moderation.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findPendingModeration = findPendingModerationFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("findPendingModerationFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should return undefined when no pending moderation exists", async () => {
|
|
17
|
-
const moderation = await findPendingModeration({
|
|
18
|
-
user_id: 1,
|
|
19
|
-
organization_id: 1,
|
|
20
|
-
type: "organization_join_block",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
assert.equal(moderation, undefined);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("should return the pending moderation", 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 moderations
|
|
43
|
-
(id, user_id, organization_id, type, status, created_at)
|
|
44
|
-
VALUES
|
|
45
|
-
(1, 1, 1, 'organization_join_block', 'pending', '4444-04-04')
|
|
46
|
-
;
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const moderation = await findPendingModeration({
|
|
50
|
-
user_id: 1,
|
|
51
|
-
organization_id: 1,
|
|
52
|
-
type: "organization_join_block",
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
assert.equal(moderation?.id, 1);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type DatabaseContext,
|
|
5
|
-
type Moderation,
|
|
6
|
-
type ModerationType,
|
|
7
|
-
} from "#src/types";
|
|
8
|
-
import { type QueryResult } from "pg";
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
export function findPendingModerationFactory({ pg }: DatabaseContext) {
|
|
13
|
-
return async function findPendingModeration({
|
|
14
|
-
user_id,
|
|
15
|
-
organization_id,
|
|
16
|
-
type,
|
|
17
|
-
}: {
|
|
18
|
-
user_id: number;
|
|
19
|
-
organization_id: number;
|
|
20
|
-
type: ModerationType;
|
|
21
|
-
}) {
|
|
22
|
-
const { rows }: QueryResult<Moderation> = await pg.query(
|
|
23
|
-
`
|
|
24
|
-
SELECT *
|
|
25
|
-
FROM moderations
|
|
26
|
-
WHERE user_id = $1
|
|
27
|
-
AND organization_id = $2
|
|
28
|
-
AND type = $3
|
|
29
|
-
AND moderated_at IS NULL;`,
|
|
30
|
-
[user_id, organization_id, type],
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
return rows.shift();
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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 { findRejectedModerationFactory } from "./find-rejected-moderation.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findRejectedModeration = findRejectedModerationFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("findRejectedModerationFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should return undefined when no rejected moderation exists", async () => {
|
|
17
|
-
const moderation = await findRejectedModeration({
|
|
18
|
-
user_id: 1,
|
|
19
|
-
organization_id: 1,
|
|
20
|
-
type: "organization_join_block",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
assert.equal(moderation, undefined);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("should return the rejected moderation", 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 moderations
|
|
43
|
-
(id, user_id, organization_id, type, status, moderated_at, created_at)
|
|
44
|
-
VALUES
|
|
45
|
-
(1, 1, 1, 'organization_join_block', 'rejected', '4444-04-04', '4444-04-04')
|
|
46
|
-
;
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const moderation = await findRejectedModeration({
|
|
50
|
-
user_id: 1,
|
|
51
|
-
organization_id: 1,
|
|
52
|
-
type: "organization_join_block",
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
assert.equal(moderation?.id, 1);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ModerationStatusSchema,
|
|
5
|
-
type DatabaseContext,
|
|
6
|
-
type Moderation,
|
|
7
|
-
type ModerationType,
|
|
8
|
-
} from "#src/types";
|
|
9
|
-
import { type QueryResult } from "pg";
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
export function findRejectedModerationFactory({ pg }: DatabaseContext) {
|
|
14
|
-
return async function findRejectedModeration({
|
|
15
|
-
user_id,
|
|
16
|
-
organization_id,
|
|
17
|
-
type,
|
|
18
|
-
}: {
|
|
19
|
-
user_id: number;
|
|
20
|
-
organization_id: number;
|
|
21
|
-
type: ModerationType;
|
|
22
|
-
}) {
|
|
23
|
-
const { rows }: QueryResult<Moderation> = await pg.query(
|
|
24
|
-
`
|
|
25
|
-
SELECT *
|
|
26
|
-
FROM moderations
|
|
27
|
-
WHERE user_id = $1
|
|
28
|
-
AND organization_id = $2
|
|
29
|
-
AND type = $3
|
|
30
|
-
AND moderated_at IS NOT NULL
|
|
31
|
-
AND status = $4;`,
|
|
32
|
-
[user_id, organization_id, type, ModerationStatusSchema.enum.rejected],
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return rows.shift();
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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 { findBySiretFactory } from "./find-by-siret.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findBySiret = findBySiretFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("findBySiretFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should find the organization by siret", async () => {
|
|
17
|
-
await pg.sql`
|
|
18
|
-
INSERT INTO organizations
|
|
19
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
20
|
-
VALUES
|
|
21
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
22
|
-
;
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
const organization = await findBySiret("⚰️");
|
|
26
|
-
|
|
27
|
-
assert.equal(organization?.id, 1);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("should return undefined when siret does not exist", async () => {
|
|
31
|
-
const organization = await findBySiret("absent");
|
|
32
|
-
|
|
33
|
-
assert.equal(organization, undefined);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { DatabaseContext, Organization } from "#src/types";
|
|
4
|
-
import { type QueryResult } from "pg";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
export function findBySiretFactory({ pg }: DatabaseContext) {
|
|
9
|
-
return async function findBySiret(siret: string) {
|
|
10
|
-
const { rows }: QueryResult<Organization> = await pg.query(
|
|
11
|
-
`
|
|
12
|
-
SELECT *
|
|
13
|
-
FROM organizations
|
|
14
|
-
WHERE siret = $1
|
|
15
|
-
`,
|
|
16
|
-
[siret],
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
return rows.shift();
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
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 { findPendingByUserIdFactory } from "./find-pending-by-user-id.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findPendingByUserId = findPendingByUserIdFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("findPendingByUserIdFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should return empty array when user has no pending moderations", async () => {
|
|
17
|
-
const organizations = await findPendingByUserId(42);
|
|
18
|
-
|
|
19
|
-
assert.deepEqual(organizations, []);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("should return pending organizations for a user", async () => {
|
|
23
|
-
await pg.sql`
|
|
24
|
-
INSERT INTO organizations
|
|
25
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
26
|
-
VALUES
|
|
27
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
28
|
-
;
|
|
29
|
-
`;
|
|
30
|
-
await pg.sql`
|
|
31
|
-
INSERT INTO users
|
|
32
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
33
|
-
VALUES
|
|
34
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
35
|
-
;
|
|
36
|
-
`;
|
|
37
|
-
await pg.sql`
|
|
38
|
-
INSERT INTO moderations
|
|
39
|
-
(id, user_id, organization_id, type, created_at, moderated_at, comment)
|
|
40
|
-
VALUES
|
|
41
|
-
(1, 1, 1, 'organization_join_block', '4444-04-04', NULL, 'pending')
|
|
42
|
-
;
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
const organizations = await findPendingByUserId(1);
|
|
46
|
-
|
|
47
|
-
assert.equal(organizations.length, 1);
|
|
48
|
-
assert.equal(organizations[0]?.id, 1);
|
|
49
|
-
assert.equal(organizations[0]?.moderation_id, 1);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { DatabaseContext } from "#src/types";
|
|
4
|
-
import { ModerationTypeSchema, type Organization } from "#src/types";
|
|
5
|
-
import { type QueryResult } from "pg";
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
export function findPendingByUserIdFactory({ pg }: DatabaseContext) {
|
|
10
|
-
return async function findPendingByUserId(user_id: number) {
|
|
11
|
-
const { rows }: QueryResult<Organization & { moderation_id: number }> =
|
|
12
|
-
await pg.query(
|
|
13
|
-
`
|
|
14
|
-
SELECT o.*, m.id as moderation_id
|
|
15
|
-
FROM moderations m
|
|
16
|
-
INNER JOIN organizations o on o.id = m.organization_id
|
|
17
|
-
WHERE m.user_id = $1
|
|
18
|
-
AND m.type = $2
|
|
19
|
-
AND m.moderated_at IS NULL
|
|
20
|
-
ORDER BY m.created_at
|
|
21
|
-
`,
|
|
22
|
-
[user_id, ModerationTypeSchema.enum.organization_join_block],
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
return rows;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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 { findByResetPasswordTokenFactory } from "./find-by-reset-password-token.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findByResetPasswordToken = findByResetPasswordTokenFactory({
|
|
11
|
-
pg: pg as any,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
suite("findByResetPasswordTokenFactory", () => {
|
|
15
|
-
before(migrate);
|
|
16
|
-
beforeEach(emptyDatabase);
|
|
17
|
-
|
|
18
|
-
test("should find a user by reset_password_token", async () => {
|
|
19
|
-
await pg.sql`
|
|
20
|
-
INSERT INTO users
|
|
21
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job, reset_password_token)
|
|
22
|
-
VALUES
|
|
23
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque', 'TOKEN')
|
|
24
|
-
;
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
const user = await findByResetPasswordToken("TOKEN");
|
|
28
|
-
|
|
29
|
-
assert.equal(user?.id, 1);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("should return undefined when the token does not exist", async () => {
|
|
33
|
-
const user = await findByResetPasswordToken("absent");
|
|
34
|
-
|
|
35
|
-
assert.equal(user, undefined);
|
|
36
|
-
});
|
|
37
|
-
});
|