@@ -28,7 +28,7 @@ const get = async (id: string): Promise<<%= compNamePascalCase %>> => {
2828 return transform ( document ) ;
2929} ;
3030
31- const updatePartial = async ( id : string , object : < %= compNamePascalCase % > ) : Promise < < %= compNamePascalCase % >> => {
31+ const updatePartial = async ( id : string , object : Omit < < %= compNamePascalCase % > , 'id' > ) : Promise < < %= compNamePascalCase % >> => {
3232 // get document
3333 const document = await Model . findById ( id ) . exec ( ) ;
3434 if ( document === null ) {
@@ -42,7 +42,7 @@ const updatePartial = async (id: string, object: <%= compNamePascalCase %>): Pro
4242 return transform ( document ) ;
4343} ;
4444
45- const update = async ( id : string , object : < %= compNamePascalCase % > ) : Promise < < %= compNamePascalCase % >> => {
45+ const update = async ( id : string , object : Omit < < %= compNamePascalCase % > , 'id' > ) : Promise < < %= compNamePascalCase % >> => {
4646 // get document
4747 const document = await Model . findById ( id ) . exec ( ) ;
4848 if ( document === null ) {
@@ -64,19 +64,18 @@ const del = async (id: string): Promise<<%= compNamePascalCase %>> => {
6464 }
6565
6666 // delete document
67- await Model . deleteOne ( { _id : id } ) . exec ( ) ;
67+ await document . remove ( ) ;
6868
6969 return transform ( document ) ;
7070} ;
7171
7272// transform document to json object
7373const transform = ( document : Document ) : < %= compNamePascalCase % > => {
74- const { _id, ...restObject } = document . toObject ( {
75- virtuals : true ,
74+ const { _id : id , ...restObject } = document . toObject ( {
7675 versionKey : false ,
7776 } ) ;
7877
79- return restObject ;
78+ return { ... restObject , id } ;
8079} ;
8180
8281export default { list , create , get , updatePartial , update , del } ;
0 commit comments