File tree 2 files changed +14
-5
lines changed
libs/json-api/json-api-nestjs/src/lib/helper
zod/zod-input-post-schema
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 1
- import { DeepPartial , Equal } from 'typeorm' ;
1
+ import { DeepPartial } from 'typeorm' ;
2
2
import {
3
3
Entity ,
4
4
ResourceObject ,
5
5
TypeormServiceObject ,
6
6
} from '../../../../types' ;
7
7
import { PostData } from '../../../zod' ;
8
- import { RelationshipsResult } from '../../../../mixin/service' ;
9
- import { ObjectTyped } from '../../../utils' ;
10
8
11
9
export async function postOne < E extends Entity > (
12
10
this : TypeormServiceObject < E > ,
13
11
inputData : PostData < E >
14
12
) : Promise < ResourceObject < E > > {
15
- const { attributes, relationships } = inputData ;
13
+ const { attributes, relationships, id } = inputData ;
14
+
15
+ const idObject = id
16
+ ? { [ this . typeormUtilsService . currentPrimaryColumn . toString ( ) ] : id }
17
+ : { } ;
18
+
19
+ const attributesObject = {
20
+ ...attributes ,
21
+ ...idObject ,
22
+ } as DeepPartial < E > ;
16
23
17
24
const entityTarget = this . repository . manager . create (
18
25
this . repository . target ,
19
- attributes as DeepPartial < E >
26
+ attributesObject
20
27
) ;
21
28
22
29
const saveData = await this . typeormUtilsService . saveEntityData (
Original file line number Diff line number Diff line change @@ -8,8 +8,10 @@ import {
8
8
zodRelationshipsSchema ,
9
9
ZodRelationshipsSchema ,
10
10
} from './relationships' ;
11
+ import { ZodIdSchema } from './id' ;
11
12
12
13
export type PostShape < E extends Entity > = {
14
+ id : ZodOptional < ZodIdSchema > ;
13
15
attributes : ZodAttributesSchema < E > ;
14
16
type : ZodTypeSchema < string > ;
15
17
relationships : ZodOptional < ZodRelationshipsSchema < E > > ;
You can’t perform that action at this time.
0 commit comments