@stamhoofd/backend 2.19.0 → 2.20.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/.env.template.json +1 -1
- package/package.json +5 -5
- package/src/crons.ts +3 -67
- package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +10 -1
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +0 -47
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +14 -16
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +1 -1
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +171 -36
- package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +2 -1
- package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +28 -32
- package/src/helpers/AdminPermissionChecker.ts +22 -5
- package/src/helpers/AuthenticatedStructures.ts +3 -2
- package/src/helpers/SetupStepsUpdater.ts +115 -13
- package/src/endpoints/global/payments/ExchangeSTPaymentEndpoint.ts +0 -153
- package/src/endpoints/organization/dashboard/organization/ApplyRegisterCodeEndpoint.test.ts +0 -64
- package/src/endpoints/organization/dashboard/organization/ApplyRegisterCodeEndpoint.ts +0 -84
- package/src/endpoints/organization/dashboard/organization/GetRegisterCodeEndpoint.ts +0 -65
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
|
-
import { Organization, RegisterCode, STCredit, UsedRegisterCode } from '@stamhoofd/models';
|
|
3
|
-
import { RegisterCodeStatus, UsedRegisterCode as UsedRegisterCodeStruct } from '@stamhoofd/structures';
|
|
4
|
-
|
|
5
|
-
import { Context } from '../../../../helpers/Context';
|
|
6
|
-
|
|
7
|
-
type Params = Record<string, never>;
|
|
8
|
-
type Query = undefined;
|
|
9
|
-
type Body = undefined;
|
|
10
|
-
type ResponseBody = RegisterCodeStatus;
|
|
11
|
-
|
|
12
|
-
export class GetRegisterCodeEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
13
|
-
|
|
14
|
-
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
15
|
-
if (request.method != "GET") {
|
|
16
|
-
return [false];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const params = Endpoint.parseParameters(request.url, "/register-code", {});
|
|
20
|
-
|
|
21
|
-
if (params) {
|
|
22
|
-
return [true, params as Params];
|
|
23
|
-
}
|
|
24
|
-
return [false];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async handle(_: DecodedRequest<Params, Query, Body>) {
|
|
28
|
-
const organization = await Context.setOrganizationScope();
|
|
29
|
-
await Context.authenticate()
|
|
30
|
-
|
|
31
|
-
if (!await Context.auth.hasSomeAccess(organization.id)) {
|
|
32
|
-
throw Context.auth.error()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const codes = await RegisterCode.where({ organizationId: organization.id })
|
|
36
|
-
let code = codes[0]
|
|
37
|
-
|
|
38
|
-
if (codes.length == 0) {
|
|
39
|
-
code = new RegisterCode()
|
|
40
|
-
code.organizationId = organization.id
|
|
41
|
-
code.description = "Doorverwezen door "+ organization.name
|
|
42
|
-
code.value = 2500
|
|
43
|
-
await code.generateCode()
|
|
44
|
-
await code.save()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const usedCodes = await UsedRegisterCode.getAll(code.code)
|
|
48
|
-
const allOrganizations = await Organization.getByIDs(...usedCodes.flatMap(u => u.organizationId ? [u.organizationId] : []))
|
|
49
|
-
const allCredits = await STCredit.getByIDs(...usedCodes.flatMap(u => u.creditId ? [u.creditId] : []))
|
|
50
|
-
|
|
51
|
-
return new Response(RegisterCodeStatus.create({
|
|
52
|
-
code: code.code,
|
|
53
|
-
value: code.value,
|
|
54
|
-
invoiceValue: code.invoiceValue,
|
|
55
|
-
usedCodes: usedCodes.map(c => {
|
|
56
|
-
return UsedRegisterCodeStruct.create({
|
|
57
|
-
id: c.id,
|
|
58
|
-
organizationName: allOrganizations.find(o => o.id === c.organizationId)?.name ?? "Onbekend",
|
|
59
|
-
createdAt: c.createdAt,
|
|
60
|
-
creditValue: (c.creditId ? allCredits.find(credit => credit.id === c.creditId)?.change : null) ?? null
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
}))
|
|
64
|
-
}
|
|
65
|
-
}
|