Skip to content

Commit 13ddb9c

Browse files
committed
chore: Update IdentitiesJsonFormsController to use POST instead of GET for retrieving a JSON Forms schema
1 parent c9c1c7b commit 13ddb9c

File tree

3 files changed

+135
-12
lines changed

3 files changed

+135
-12
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
type: Group
2+
label: supannPerson
3+
elements:
4+
- type: HorizontalLayout
5+
elements:
6+
- type: Control
7+
label: Civilitéaaaaaaaaaaa
8+
scope: "#/properties/supanncivilite"
9+
options:
10+
required: true
11+
suggestion:
12+
- M.
13+
- Mme
14+
- Mlle
15+
- type: Control
16+
label: supannNomdeNaissance
17+
scope: "#/properties/supannNomdeNaissance"
18+
options:
19+
required: false
20+
- type: Control
21+
label: supannOIDCDatedeNaissance
22+
scope: "#/properties/supannOIDCDatedeNaissance"
23+
options:
24+
format: date
25+
required: true
26+
dateFormat: "dd/MM/yyyy"
27+
- type: HorizontalLayout
28+
elements:
29+
- type: Control
30+
label: supannOIDCGenre
31+
scope: "#/properties/supannOIDCGenre"
32+
options:
33+
required: true
34+
- type: Control
35+
label: supannPrenomsEtatCivil
36+
scope: "#/properties/supannPrenomsEtatCivil"
37+
options:
38+
required: true
39+
- type: Control
40+
label: supannCodeINSEEPaysDeNaissance
41+
scope: "#/properties/supannCodeINSEEPaysDeNaissance"
42+
options:
43+
required: true
44+
- type: HorizontalLayout
45+
elements:
46+
- type: Control
47+
label: supannCodeINSEEVilleDeNaissance
48+
scope: "#/properties/supannCodeINSEEVilleDeNaissance"
49+
options:
50+
required: false
51+
- type: Control
52+
label: supannAutreMail
53+
scope: "#/properties/supannAutreMail"
54+
options:
55+
required: true
56+
- type: Control
57+
label: supannListeRouge
58+
scope: "#/properties/supannListeRouge"
59+
options:
60+
required: false
61+
- type: HorizontalLayout
62+
elements:
63+
- type: Control
64+
label: mailForwardingAddress
65+
scope: "#/properties/mailForwardingAddress"
66+
options:
67+
required: false
68+
- type: Control
69+
label: supannMailPerso
70+
scope: "#/properties/supannMailPerso"
71+
options:
72+
required: false
73+
- type: Control
74+
label: supannRoleGenerique
75+
scope: "#/properties/supannRoleGenerique"
76+
options:
77+
required: false
78+
- type: HorizontalLayout
79+
elements:
80+
- type: Control
81+
label: supannEmpId
82+
scope: "#/properties/supannEmpId"
83+
options:
84+
format: number
85+
required: false
86+
- type: Control
87+
label: supannParrainDN
88+
scope: "#/properties/supannParrainDN"
89+
options:
90+
required: false
91+
- type: Control
92+
label: supannTypeEntiteAffectation
93+
scope: "#/properties/supannTypeEntiteAffectation"
94+
options:
95+
required: false
96+
readOnly: true
97+
suggestion:
98+
- "adm"
99+
- "etd"
100+
- "esn"
101+
- type: HorizontalLayout
102+
elements:
103+
- type: Control
104+
label: supannActivite
105+
scope: "#/properties/supannActivite"
106+
options:
107+
required: false
108+
- type: Control
109+
label: supannEmpDateFin
110+
scope: "#/properties/supannEmpDateFin"
111+
options:
112+
required: false

src/management/identities/jsonforms/identities.jsonforms.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AbstractController } from '~/_common/abstracts/abstract.controller';
33
import { IdentitiesJsonformsService } from './identities.jsonforms.service';
44
import { Response } from 'express';
55
import { ApiOperation, ApiTags } from '@nestjs/swagger';
6+
import { IdentitiesUpdateDto } from '../_dto/identities.dto';
67

78
@ApiTags('management/identities/jsonforms')
89
@Controller('management/identities/jsonforms')
@@ -48,8 +49,9 @@ export class IdentitiesJsonFormsController extends AbstractController {
4849
@Res() res: Response,
4950
@Param('schema') schema,
5051
@Query('mode') mode: 'create' | 'update',
52+
@Body() body: Partial<IdentitiesUpdateDto>,
5153
): Promise<any> {
52-
const result = await this._service.findOne(schema, { mode });
54+
const result = await this._service.findOne(schema, { mode, employeeType: body?.inetOrgPerson?.employeeType });
5355
return res.status(HttpStatus.OK).json({
5456
statusCode: HttpStatus.OK,
5557
data: result,

src/management/identities/jsonforms/identities.jsonforms.service.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,33 @@ export class IdentitiesJsonformsService extends AbstractService {
153153
return [result, files.length];
154154
}
155155

156-
public async findOne(schema, options?: { mode: string }): Promise<any> {
157-
options = {
158-
mode: 'create',
159-
...options,
160-
};
161-
156+
public async findOne(
157+
schema: string,
158+
options?: { mode?: string; employeeType?: string }
159+
): Promise<any> {
160+
const { mode = 'create', employeeType = '' } = options || {};
162161
if (schema.endsWith('.yml')) schema = schema.replace('.yml', '');
163162

164-
let filePath = this.resolveJsonFormPath(schema + '.' + options?.mode + '.ui');
163+
const filePaths = [
164+
`${schema}.${mode}.${employeeType.toLowerCase()}.ui`,
165+
`${schema}.${mode}.ui`,
166+
`${schema}.${employeeType.toLowerCase()}.ui`,
167+
`${schema}.ui`,
168+
];
165169

166-
if (!filePath) {
167-
filePath = this.resolveJsonFormPath(schema + '.ui');
168-
}
170+
let finalPath = null;
171+
const filePath = filePaths.find((path) => {
172+
const resolved = this.resolveJsonFormPath(path)
173+
if (!resolved) return null;
174+
finalPath = resolved;
175+
176+
return resolved;
177+
});
169178

170179
if (!filePath) {
171180
throw new ValidationConfigException({ message: `File not found: ${schema}.ui.yml` });
172181
}
173182

174-
return parse(readFileSync(filePath, 'utf-8'));
183+
return parse(readFileSync(finalPath, 'utf-8'));
175184
}
176185
}

0 commit comments

Comments
 (0)