File tree 4 files changed +14
-12
lines changed
libs/json-api/json-api-nestjs/src/lib
4 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -19,4 +19,5 @@ export const ConfigParamDefault: ConfigParam = {
19
19
debug : true ,
20
20
requiredSelectField : true ,
21
21
pipeForId : ParseIntPipe ,
22
+ useSoftDelete : false ,
22
23
} ;
Original file line number Diff line number Diff line change 1
1
import { Entity , TypeormServiceObject } from '../../../../types' ;
2
+ import { FindOptionsWhere } from 'typeorm' ;
2
3
3
4
export async function deleteOne < E extends Entity > (
4
5
this : TypeormServiceObject < E > ,
5
6
id : number | string
6
7
) : Promise < void > {
7
- await this . repository
8
- . createQueryBuilder ( this . typeormUtilsService . currentAlias )
9
- . delete ( )
10
- . where (
11
- `${ this . typeormUtilsService . currentPrimaryColumn . toString ( ) } = :params`
12
- )
13
- . setParameters ( {
14
- params : id ,
15
- } )
16
- . execute ( ) ;
8
+ const data = await this . repository . findOne ( {
9
+ where : {
10
+ [ this . typeormUtilsService . currentPrimaryColumn . toString ( ) ] : id ,
11
+ } as FindOptionsWhere < E > ,
12
+ } ) ;
13
+ if ( ! data ) return void 0 ;
14
+
15
+ this . config . useSoftDelete
16
+ ? await this . repository . softRemove ( data )
17
+ : await this . repository . remove ( data ) ;
18
+
17
19
return void 0 ;
18
20
}
Original file line number Diff line number Diff line change 9
9
SUB_QUERY_ALIAS_FOR_PAGINATION ,
10
10
} from '../../../../constants' ;
11
11
import { ResourceObject } from '../../../../types/response' ;
12
- import { da } from '@faker-js/faker' ;
13
12
14
13
type OrderByCondition = Record < string , 'ASC' | 'DESC' > ;
15
14
@@ -250,7 +249,6 @@ export async function getAll<E extends Entity>(
250
249
) ;
251
250
}
252
251
const resultData = await resultQuery . getMany ( ) ;
253
- console . log ( resultData ) ;
254
252
const { included, data } =
255
253
this . transformDataService . transformData ( resultData ) ;
256
254
return {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export type ExtractNestType<ArrayType> =
20
20
export interface ConfigParam {
21
21
requiredSelectField : boolean ;
22
22
debug : boolean ;
23
+ useSoftDelete : boolean ;
23
24
pipeForId : PipeMixin ;
24
25
operationUrl ?: string ;
25
26
overrideRoute ?: string ;
You can’t perform that action at this time.
0 commit comments