File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
libs/json-api/json-api-nestjs/src/lib/helper
zod/zod-input-post-schema Expand file tree Collapse file tree 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' ;
22import {
33 Entity ,
44 ResourceObject ,
55 TypeormServiceObject ,
66} from '../../../../types' ;
77import { PostData } from '../../../zod' ;
8- import { RelationshipsResult } from '../../../../mixin/service' ;
9- import { ObjectTyped } from '../../../utils' ;
108
119export async function postOne < E extends Entity > (
1210 this : TypeormServiceObject < E > ,
1311 inputData : PostData < E >
1412) : 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 > ;
1623
1724 const entityTarget = this . repository . manager . create (
1825 this . repository . target ,
19- attributes as DeepPartial < E >
26+ attributesObject
2027 ) ;
2128
2229 const saveData = await this . typeormUtilsService . saveEntityData (
Original file line number Diff line number Diff line change @@ -8,8 +8,10 @@ import {
88 zodRelationshipsSchema ,
99 ZodRelationshipsSchema ,
1010} from './relationships' ;
11+ import { ZodIdSchema } from './id' ;
1112
1213export type PostShape < E extends Entity > = {
14+ id : ZodOptional < ZodIdSchema > ;
1315 attributes : ZodAttributesSchema < E > ;
1416 type : ZodTypeSchema < string > ;
1517 relationships : ZodOptional < ZodRelationshipsSchema < E > > ;
You can’t perform that action at this time.
0 commit comments