@forklaunch/implementation-iam-base 0.1.12 → 0.1.13

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.
Files changed (75) hide show
  1. package/lib/__test__/schemaEquality.test.d.ts +2 -0
  2. package/lib/__test__/schemaEquality.test.d.ts.map +1 -0
  3. package/lib/__test__/schemaEquality.test.js +183 -0
  4. package/lib/eject/domain/schemas/index.ts +4 -0
  5. package/lib/eject/domain/schemas/organization.schema.ts +53 -0
  6. package/lib/eject/domain/schemas/permission.schema.ts +36 -0
  7. package/lib/eject/domain/schemas/role.schema.ts +37 -0
  8. package/lib/eject/domain/schemas/user.schema.ts +53 -0
  9. package/lib/eject/services/index.ts +4 -0
  10. package/lib/eject/services/organization.service.ts +143 -0
  11. package/lib/eject/services/permission.service.ts +345 -0
  12. package/lib/eject/services/role.service.ts +179 -0
  13. package/lib/eject/services/user.service.ts +224 -0
  14. package/lib/jest.config.d.ts +4 -0
  15. package/lib/jest.config.d.ts.map +1 -0
  16. package/lib/jest.config.js +19 -0
  17. package/lib/schemas/index.d.ts +5 -0
  18. package/lib/schemas/index.d.ts.map +1 -0
  19. package/lib/schemas/index.js +4 -0
  20. package/lib/schemas/organization.schema.d.ts +200 -0
  21. package/lib/schemas/organization.schema.d.ts.map +1 -0
  22. package/lib/schemas/organization.schema.js +4 -0
  23. package/lib/schemas/permission.schema.d.ts +50 -0
  24. package/lib/schemas/permission.schema.d.ts.map +1 -0
  25. package/lib/schemas/permission.schema.js +4 -0
  26. package/lib/schemas/role.schema.d.ts +74 -0
  27. package/lib/schemas/role.schema.d.ts.map +1 -0
  28. package/lib/schemas/role.schema.js +4 -0
  29. package/lib/schemas/typebox/organization.schema.d.ts +112 -0
  30. package/lib/schemas/typebox/organization.schema.d.ts.map +1 -0
  31. package/lib/schemas/typebox/organization.schema.js +34 -0
  32. package/lib/schemas/typebox/permission.schema.d.ts +47 -0
  33. package/lib/schemas/typebox/permission.schema.d.ts.map +1 -0
  34. package/lib/schemas/typebox/permission.schema.js +25 -0
  35. package/lib/schemas/typebox/role.schema.d.ts +59 -0
  36. package/lib/schemas/typebox/role.schema.d.ts.map +1 -0
  37. package/lib/schemas/typebox/role.schema.js +26 -0
  38. package/lib/schemas/typebox/user.schema.d.ts +103 -0
  39. package/lib/schemas/typebox/user.schema.d.ts.map +1 -0
  40. package/lib/schemas/typebox/user.schema.js +41 -0
  41. package/lib/schemas/user.schema.d.ts +144 -0
  42. package/lib/schemas/user.schema.d.ts.map +1 -0
  43. package/lib/schemas/user.schema.js +4 -0
  44. package/lib/schemas/zod/organization.schema.d.ts +284 -0
  45. package/lib/schemas/zod/organization.schema.d.ts.map +1 -0
  46. package/lib/schemas/zod/organization.schema.js +34 -0
  47. package/lib/schemas/zod/permission.schema.d.ts +47 -0
  48. package/lib/schemas/zod/permission.schema.d.ts.map +1 -0
  49. package/lib/schemas/zod/permission.schema.js +25 -0
  50. package/lib/schemas/zod/role.schema.d.ts +83 -0
  51. package/lib/schemas/zod/role.schema.d.ts.map +1 -0
  52. package/lib/schemas/zod/role.schema.js +26 -0
  53. package/lib/schemas/zod/user.schema.d.ts +179 -0
  54. package/lib/schemas/zod/user.schema.d.ts.map +1 -0
  55. package/lib/schemas/zod/user.schema.js +41 -0
  56. package/lib/services/index.d.ts +5 -0
  57. package/lib/services/index.d.ts.map +1 -0
  58. package/lib/services/index.js +4 -0
  59. package/lib/services/organization.service.d.ts +45 -0
  60. package/lib/services/organization.service.d.ts.map +1 -0
  61. package/lib/services/organization.service.js +35 -0
  62. package/lib/services/permission.service.d.ts +62 -0
  63. package/lib/services/permission.service.d.ts.map +1 -0
  64. package/lib/services/permission.service.js +159 -0
  65. package/lib/services/role.service.d.ts +49 -0
  66. package/lib/services/role.service.d.ts.map +1 -0
  67. package/lib/services/role.service.js +57 -0
  68. package/lib/services/user.service.d.ts +54 -0
  69. package/lib/services/user.service.d.ts.map +1 -0
  70. package/lib/services/user.service.js +85 -0
  71. package/lib/tsconfig.tsbuildinfo +1 -0
  72. package/lib/vitest.config.d.ts +3 -0
  73. package/lib/vitest.config.d.ts.map +1 -0
  74. package/lib/vitest.config.js +7 -0
  75. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schemaEquality.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEquality.test.d.ts","sourceRoot":"","sources":["../../__test__/schemaEquality.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,183 @@
1
+ import { isTrue } from '@forklaunch/common';
2
+ import { DummyEnum, testSchemaEquality } from '@forklaunch/core/test';
3
+ import { CreateOrganizationSchema as TypeboxCreateOrganizationSchema, OrganizationSchema as TypeboxOrganizationSchema, UpdateOrganizationSchema as TypeboxUpdateOrganizationSchema } from '../schemas/typebox/organization.schema';
4
+ import { CreatePermissionSchema as TypeboxCreatePermissionSchema, PermissionSchema as TypeboxPermissionSchema, UpdatePermissionSchema as TypeboxUpdatePermissionSchema } from '../schemas/typebox/permission.schema';
5
+ import { CreateRoleSchema as TypeboxCreateRoleSchema, RoleSchema as TypeboxRoleSchema, UpdateRoleSchema as TypeboxUpdateRoleSchema } from '../schemas/typebox/role.schema';
6
+ import { CreateUserSchema as TypeboxCreateUserSchema, UpdateUserSchema as TypeboxUpdateUserSchema, UserSchema as TypeboxUserSchema } from '../schemas/typebox/user.schema';
7
+ import { CreateOrganizationSchema as ZodCreateOrganizationSchema, OrganizationSchema as ZodOrganizationSchema, UpdateOrganizationSchema as ZodUpdateOrganizationSchema } from '../schemas/zod/organization.schema';
8
+ import { CreatePermissionSchema as ZodCreatePermissionSchema, PermissionSchema as ZodPermissionSchema, UpdatePermissionSchema as ZodUpdatePermissionSchema } from '../schemas/zod/permission.schema';
9
+ import { CreateRoleSchema as ZodCreateRoleSchema, RoleSchema as ZodRoleSchema, UpdateRoleSchema as ZodUpdateRoleSchema } from '../schemas/zod/role.schema';
10
+ import { CreateUserSchema as ZodCreateUserSchema, UpdateUserSchema as ZodUpdateUserSchema, UserSchema as ZodUserSchema } from '../schemas/zod/user.schema';
11
+ const zodUpdatePermissionSchema = ZodUpdatePermissionSchema({
12
+ uuidId: false
13
+ });
14
+ const typeboxUpdatePermissionSchema = TypeboxUpdatePermissionSchema({
15
+ uuidId: false
16
+ });
17
+ const zodPermissionSchema = ZodPermissionSchema({ uuidId: false });
18
+ const typeboxPermissionSchema = TypeboxPermissionSchema({ uuidId: false });
19
+ const zodUpdateRoleSchema = ZodUpdateRoleSchema({ uuidId: false });
20
+ const typeboxUpdateRoleSchema = TypeboxUpdateRoleSchema({ uuidId: false });
21
+ const zodRoleSchema = ZodRoleSchema({ uuidId: false });
22
+ const typeboxRoleSchema = TypeboxRoleSchema({ uuidId: false });
23
+ const zodUpdateUserSchema = ZodUpdateUserSchema({ uuidId: false });
24
+ const typeboxUpdateUserSchema = TypeboxUpdateUserSchema({ uuidId: false });
25
+ const zodUserSchema = ZodUserSchema({ uuidId: false });
26
+ const typeboxUserSchema = TypeboxUserSchema({ uuidId: false });
27
+ const zodUpdateOrganizationSchema = ZodUpdateOrganizationSchema({
28
+ uuidId: false
29
+ });
30
+ const typeboxUpdateOrganizationSchema = TypeboxUpdateOrganizationSchema({
31
+ uuidId: false
32
+ });
33
+ const zodOrganizationSchema = ZodOrganizationSchema({ uuidId: false })(DummyEnum);
34
+ const typeboxOrganizationSchema = TypeboxOrganizationSchema({ uuidId: false })(DummyEnum);
35
+ describe('schema equality', () => {
36
+ it('should be equal for permission', () => {
37
+ expect(isTrue(testSchemaEquality(ZodCreatePermissionSchema, TypeboxCreatePermissionSchema, {
38
+ slug: 'test',
39
+ addToRolesIds: ['test'],
40
+ extraFields: {
41
+ test: 'test'
42
+ }
43
+ }))).toBeTruthy();
44
+ expect(isTrue(testSchemaEquality(zodUpdatePermissionSchema, typeboxUpdatePermissionSchema, {
45
+ id: 'test',
46
+ slug: 'test',
47
+ addToRolesIds: ['test'],
48
+ removeFromRolesIds: ['test'],
49
+ extraFields: {
50
+ test: 'test'
51
+ }
52
+ }))).toBeTruthy();
53
+ expect(isTrue(testSchemaEquality(zodPermissionSchema, typeboxPermissionSchema, {
54
+ id: 'test',
55
+ slug: 'test',
56
+ extraFields: {
57
+ test: 'test'
58
+ }
59
+ }))).toBeTruthy();
60
+ });
61
+ it('should be equal for role', () => {
62
+ expect(isTrue(testSchemaEquality(ZodCreateRoleSchema, TypeboxCreateRoleSchema, {
63
+ name: 'test',
64
+ permissionIds: ['test'],
65
+ extraFields: {
66
+ test: 'test'
67
+ }
68
+ }))).toBeTruthy();
69
+ expect(isTrue(testSchemaEquality(zodUpdateRoleSchema, typeboxUpdateRoleSchema, {
70
+ id: 'test',
71
+ name: 'test',
72
+ permissionIds: ['test'],
73
+ extraFields: {
74
+ test: 'test'
75
+ }
76
+ }))).toBeTruthy();
77
+ expect(isTrue(testSchemaEquality(zodRoleSchema, typeboxRoleSchema, {
78
+ id: 'test',
79
+ name: 'test',
80
+ permissions: [
81
+ {
82
+ id: 'test',
83
+ slug: 'test',
84
+ extraFields: { test: 'test' }
85
+ }
86
+ ],
87
+ extraFields: {
88
+ test: 'test'
89
+ }
90
+ }))).toBeTruthy();
91
+ });
92
+ it('should be equal for user', () => {
93
+ expect(isTrue(testSchemaEquality(ZodCreateUserSchema, TypeboxCreateUserSchema, {
94
+ email: 'test@test.com',
95
+ password: 'test',
96
+ firstName: 'test',
97
+ lastName: 'test',
98
+ organizationId: 'test',
99
+ roleIds: ['test'],
100
+ phoneNumber: 'test',
101
+ subscription: 'test',
102
+ extraFields: {
103
+ test: 'test'
104
+ }
105
+ }))).toBeTruthy();
106
+ expect(isTrue(testSchemaEquality(zodUpdateUserSchema, typeboxUpdateUserSchema, {
107
+ id: 'test',
108
+ email: 'test@test.com',
109
+ password: 'test',
110
+ firstName: 'test',
111
+ lastName: 'test',
112
+ roleIds: ['test'],
113
+ phoneNumber: 'test',
114
+ subscription: 'test',
115
+ extraFields: {
116
+ test: 'test'
117
+ }
118
+ }))).toBeTruthy();
119
+ expect(isTrue(testSchemaEquality(zodUserSchema, typeboxUserSchema, {
120
+ id: 'test',
121
+ email: 'test@test.com',
122
+ firstName: 'test',
123
+ lastName: 'test',
124
+ roles: [
125
+ {
126
+ id: 'test',
127
+ name: 'test',
128
+ permissions: [{ id: 'test', slug: 'test' }],
129
+ extraFields: {
130
+ test: 'test'
131
+ }
132
+ }
133
+ ],
134
+ phoneNumber: 'test',
135
+ subscription: 'test',
136
+ extraFields: {
137
+ test: 'test'
138
+ }
139
+ }))).toBeTruthy();
140
+ });
141
+ it('should be equal for organization', () => {
142
+ expect(isTrue(testSchemaEquality(ZodCreateOrganizationSchema, TypeboxCreateOrganizationSchema, {
143
+ name: 'test',
144
+ domain: 'test',
145
+ subscription: 'test',
146
+ logoUrl: 'test',
147
+ extraFields: { test: 'test' }
148
+ }))).toBeTruthy();
149
+ expect(isTrue(testSchemaEquality(zodUpdateOrganizationSchema, typeboxUpdateOrganizationSchema, {
150
+ id: 'test',
151
+ name: 'test',
152
+ domain: 'test',
153
+ subscription: 'test',
154
+ logoUrl: 'test',
155
+ extraFields: { test: 'test' }
156
+ }))).toBeTruthy();
157
+ expect(isTrue(testSchemaEquality(zodOrganizationSchema, typeboxOrganizationSchema, {
158
+ id: 'test',
159
+ name: 'test',
160
+ domain: 'test',
161
+ subscription: 'test',
162
+ logoUrl: 'test',
163
+ extraFields: { test: 'test' },
164
+ status: DummyEnum.A,
165
+ users: [
166
+ {
167
+ id: 'test',
168
+ email: 'test@test.com',
169
+ firstName: 'test',
170
+ lastName: 'test',
171
+ roles: [
172
+ {
173
+ id: 'test',
174
+ name: 'test',
175
+ permissions: [{ id: 'test', slug: 'test' }],
176
+ extraFields: { test: 'test' }
177
+ }
178
+ ]
179
+ }
180
+ ]
181
+ }))).toBeTruthy();
182
+ });
183
+ });
@@ -0,0 +1,4 @@
1
+ export * from './organization.schema';
2
+ export * from './permission.schema';
3
+ export * from './role.schema';
4
+ export * from './user.schema';
@@ -0,0 +1,53 @@
1
+ import { LiteralSchema } from '@forklaunch/validator';
2
+ import {
3
+ array,
4
+ date,
5
+ enum_,
6
+ optional,
7
+ string,
8
+ unknown,
9
+ uuid
10
+ } from '@{{app_name}}/core';
11
+ import { UserSchema } from './user.schema';
12
+
13
+ export const CreateOrganizationSchema = {
14
+ name: string,
15
+ domain: string,
16
+ subscription: string,
17
+ logoUrl: optional(string),
18
+ extraFields: optional(unknown)
19
+ };
20
+
21
+ export const UpdateOrganizationSchema = ({ uuidId }: { uuidId: boolean }) => ({
22
+ id: uuidId ? uuid : string,
23
+ name: optional(string),
24
+ domain: optional(string),
25
+ subscription: optional(string),
26
+ logoUrl: optional(string),
27
+ extraFields: optional(unknown)
28
+ });
29
+
30
+ export const OrganizationSchema =
31
+ ({ uuidId }: { uuidId: boolean }) =>
32
+ <OrganizationStatus extends Record<string, LiteralSchema>>(
33
+ organizationStatus: OrganizationStatus
34
+ ) => ({
35
+ id: uuidId ? uuid : string,
36
+ name: string,
37
+ users: array(UserSchema({ uuidId })),
38
+ domain: string,
39
+ subscription: string,
40
+ status: enum_(organizationStatus),
41
+ logoUrl: optional(string),
42
+ extraFields: optional(unknown),
43
+ createdAt: optional(date),
44
+ updatedAt: optional(date)
45
+ });
46
+
47
+ export const BaseOrganizationServiceSchemas = (options: {
48
+ uuidId: boolean;
49
+ }) => ({
50
+ CreateOrganizationSchema,
51
+ UpdateOrganizationSchema: UpdateOrganizationSchema(options),
52
+ OrganizationSchema: OrganizationSchema(options)
53
+ });
@@ -0,0 +1,36 @@
1
+ import {
2
+ array,
3
+ date,
4
+ optional,
5
+ string,
6
+ unknown,
7
+ uuid
8
+ } from '@{{app_name}}/core';
9
+
10
+ export const CreatePermissionSchema = {
11
+ slug: string,
12
+ addToRolesIds: optional(array(string)),
13
+ extraFields: optional(unknown)
14
+ };
15
+
16
+ export const UpdatePermissionSchema = ({ uuidId }: { uuidId: boolean }) => ({
17
+ id: uuidId ? uuid : string,
18
+ slug: optional(string),
19
+ extraFields: optional(unknown),
20
+ addToRolesIds: optional(array(string)),
21
+ removeFromRolesIds: optional(array(string))
22
+ });
23
+
24
+ export const PermissionSchema = ({ uuidId }: { uuidId: boolean }) => ({
25
+ id: uuidId ? uuid : string,
26
+ slug: string,
27
+ extraFields: optional(unknown),
28
+ createdAt: optional(date),
29
+ updatedAt: optional(date)
30
+ });
31
+
32
+ export const BasePermissionServiceSchemas = (options: { uuidId: boolean }) => ({
33
+ CreatePermissionSchema,
34
+ UpdatePermissionSchema: UpdatePermissionSchema(options),
35
+ PermissionSchema: PermissionSchema(options)
36
+ });
@@ -0,0 +1,37 @@
1
+ import {
2
+ array,
3
+ date,
4
+ optional,
5
+ string,
6
+ unknown,
7
+ uuid
8
+ } from '@{{app_name}}/core';
9
+ import { PermissionSchema } from './permission.schema';
10
+
11
+ export const CreateRoleSchema = {
12
+ name: string,
13
+ permissionIds: optional(array(string)),
14
+ extraFields: optional(unknown)
15
+ };
16
+
17
+ export const UpdateRoleSchema = ({ uuidId }: { uuidId: boolean }) => ({
18
+ id: uuidId ? uuid : string,
19
+ name: optional(string),
20
+ permissionIds: optional(array(string)),
21
+ extraFields: optional(unknown)
22
+ });
23
+
24
+ export const RoleSchema = ({ uuidId }: { uuidId: boolean }) => ({
25
+ id: uuidId ? uuid : string,
26
+ name: string,
27
+ permissions: array(PermissionSchema({ uuidId })),
28
+ extraFields: optional(unknown),
29
+ createdAt: optional(date),
30
+ updatedAt: optional(date)
31
+ });
32
+
33
+ export const BaseRoleServiceSchemas = (options: { uuidId: boolean }) => ({
34
+ CreateRoleSchema,
35
+ UpdateRoleSchema: UpdateRoleSchema(options),
36
+ RoleSchema: RoleSchema(options)
37
+ });
@@ -0,0 +1,53 @@
1
+ import {
2
+ array,
3
+ date,
4
+ email,
5
+ optional,
6
+ string,
7
+ unknown,
8
+ uuid
9
+ } from '@{{app_name}}/core';
10
+ import { RoleSchema } from './role.schema';
11
+
12
+ export const CreateUserSchema = {
13
+ email: email,
14
+ password: string,
15
+ firstName: string,
16
+ lastName: string,
17
+ organizationId: string,
18
+ roleIds: array(string),
19
+ phoneNumber: optional(string),
20
+ subscription: optional(string),
21
+ extraFields: optional(unknown)
22
+ };
23
+
24
+ export const UpdateUserSchema = ({ uuidId }: { uuidId: boolean }) => ({
25
+ id: uuidId ? uuid : string,
26
+ email: optional(email),
27
+ password: optional(string),
28
+ firstName: optional(string),
29
+ lastName: optional(string),
30
+ roleIds: optional(array(string)),
31
+ phoneNumber: optional(string),
32
+ subscription: optional(string),
33
+ extraFields: optional(unknown)
34
+ });
35
+
36
+ export const UserSchema = ({ uuidId }: { uuidId: boolean }) => ({
37
+ id: uuidId ? uuid : string,
38
+ email: email,
39
+ firstName: string,
40
+ lastName: string,
41
+ roles: array(RoleSchema({ uuidId })),
42
+ phoneNumber: optional(string),
43
+ subscription: optional(string),
44
+ extraFields: optional(unknown),
45
+ createdAt: optional(date),
46
+ updatedAt: optional(date)
47
+ });
48
+
49
+ export const BaseUserServiceSchemas = (options: { uuidId: boolean }) => ({
50
+ CreateUserSchema,
51
+ UpdateUserSchema: UpdateUserSchema(options),
52
+ UserSchema: UserSchema(options)
53
+ });
@@ -0,0 +1,4 @@
1
+ export * from './organization.service';
2
+ export * from './permission.service';
3
+ export * from './role.service';
4
+ export * from './user.service';
@@ -0,0 +1,143 @@
1
+ import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
2
+ import {
3
+ InternalDtoMapper,
4
+ RequestDtoMapperConstructor,
5
+ ResponseDtoMapperConstructor,
6
+ transformIntoInternalDtoMapper
7
+ } from '@forklaunch/core/mappers';
8
+ import {
9
+ MetricsDefinition,
10
+ OpenTelemetryCollector
11
+ } from '@forklaunch/core/http';
12
+ import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
13
+ import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
14
+ import {
15
+ CreateOrganizationDto,
16
+ OrganizationDto,
17
+ UpdateOrganizationDto
18
+ } from '@forklaunch/interfaces-iam/types';
19
+ import { AnySchemaValidator } from '@forklaunch/validator';
20
+ import { EntityManager } from '@mikro-orm/core';
21
+
22
+ export class BaseOrganizationService<
23
+ SchemaValidator extends AnySchemaValidator,
24
+ OrganizationStatus,
25
+ Metrics extends MetricsDefinition = MetricsDefinition,
26
+ Dto extends {
27
+ OrganizationDtoMapper: OrganizationDto<OrganizationStatus>;
28
+ CreateOrganizationDtoMapper: CreateOrganizationDto;
29
+ UpdateOrganizationDtoMapper: UpdateOrganizationDto;
30
+ } = {
31
+ OrganizationDtoMapper: OrganizationDto<OrganizationStatus>;
32
+ CreateOrganizationDtoMapper: CreateOrganizationDto;
33
+ UpdateOrganizationDtoMapper: UpdateOrganizationDto;
34
+ },
35
+ Entities extends {
36
+ OrganizationDtoMapper: MapNestedDtoArraysToCollections<
37
+ OrganizationDto<OrganizationStatus>,
38
+ 'users'
39
+ >;
40
+ CreateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
41
+ OrganizationDto<OrganizationStatus>,
42
+ 'users'
43
+ >;
44
+ UpdateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
45
+ OrganizationDto<OrganizationStatus>,
46
+ 'users'
47
+ >;
48
+ } = {
49
+ OrganizationDtoMapper: MapNestedDtoArraysToCollections<
50
+ OrganizationDto<OrganizationStatus>,
51
+ 'users'
52
+ >;
53
+ CreateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
54
+ OrganizationDto<OrganizationStatus>,
55
+ 'users'
56
+ >;
57
+ UpdateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
58
+ OrganizationDto<OrganizationStatus>,
59
+ 'users'
60
+ >;
61
+ }
62
+ > implements OrganizationService<OrganizationStatus>
63
+ {
64
+ #mapperss: InternalDtoMapper<
65
+ InstanceTypeRecord<typeof this.mapperss>,
66
+ Entities,
67
+ Dto
68
+ >;
69
+
70
+ constructor(
71
+ public em: EntityManager,
72
+ protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
73
+ protected schemaValidator: SchemaValidator,
74
+ protected mapperss: {
75
+ OrganizationDtoMapper: ResponseDtoMapperConstructor<
76
+ SchemaValidator,
77
+ Dto['OrganizationDtoMapper'],
78
+ Entities['OrganizationDtoMapper']
79
+ >;
80
+ CreateOrganizationDtoMapper: RequestDtoMapperConstructor<
81
+ SchemaValidator,
82
+ Dto['CreateOrganizationDtoMapper'],
83
+ Entities['CreateOrganizationDtoMapper']
84
+ >;
85
+ UpdateOrganizationDtoMapper: RequestDtoMapperConstructor<
86
+ SchemaValidator,
87
+ Dto['UpdateOrganizationDtoMapper'],
88
+ Entities['UpdateOrganizationDtoMapper']
89
+ >;
90
+ }
91
+ ) {
92
+ this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
93
+ }
94
+
95
+ async createOrganization(
96
+ organizationDto: Dto['CreateOrganizationDtoMapper'],
97
+ em?: EntityManager
98
+ ): Promise<Dto['OrganizationDtoMapper']> {
99
+ this.openTelemetryCollector.log('info', 'Creating organization');
100
+ const organization =
101
+ this.#mapperss.CreateOrganizationDtoMapper.deserializeDtoToEntity(
102
+ organizationDto
103
+ );
104
+ await (em ?? this.em).transactional(async (innerEm) => {
105
+ await innerEm.persist(organization);
106
+ });
107
+
108
+ return this.#mapperss.OrganizationDtoMapper.serializeEntityToDto(
109
+ organization
110
+ );
111
+ }
112
+
113
+ async getOrganization(
114
+ idDto: IdDto,
115
+ em?: EntityManager
116
+ ): Promise<Dto['OrganizationDtoMapper']> {
117
+ const organization = await (em ?? this.em).findOneOrFail(
118
+ 'Organization',
119
+ idDto
120
+ );
121
+ return this.#mapperss.OrganizationDtoMapper.serializeEntityToDto(
122
+ organization as Entities['OrganizationDtoMapper']
123
+ );
124
+ }
125
+
126
+ async updateOrganization(
127
+ organizationDto: Dto['UpdateOrganizationDtoMapper'],
128
+ em?: EntityManager
129
+ ): Promise<Dto['OrganizationDtoMapper']> {
130
+ const updatedOrganization =
131
+ this.#mapperss.UpdateOrganizationDtoMapper.deserializeDtoToEntity(
132
+ organizationDto
133
+ );
134
+ await (em ?? this.em).upsert(updatedOrganization);
135
+ return this.#mapperss.OrganizationDtoMapper.serializeEntityToDto(
136
+ updatedOrganization
137
+ );
138
+ }
139
+
140
+ async deleteOrganization(idDto: IdDto, em?: EntityManager): Promise<void> {
141
+ await (em ?? this.em).nativeDelete('Organization', idDto);
142
+ }
143
+ }