File tree Expand file tree Collapse file tree 4 files changed +14
-12
lines changed
libs/json-api/json-api-nestjs/src/lib Expand file tree Collapse file tree 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 = {
1919 debug : true ,
2020 requiredSelectField : true ,
2121 pipeForId : ParseIntPipe ,
22+ useSoftDelete : false ,
2223} ;
Original file line number Diff line number Diff line change 11import { Entity , TypeormServiceObject } from '../../../../types' ;
2+ import { FindOptionsWhere } from 'typeorm' ;
23
34export async function deleteOne < E extends Entity > (
45 this : TypeormServiceObject < E > ,
56 id : number | string
67) : 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+
1719 return void 0 ;
1820}
Original file line number Diff line number Diff line change 99 SUB_QUERY_ALIAS_FOR_PAGINATION ,
1010} from '../../../../constants' ;
1111import { ResourceObject } from '../../../../types/response' ;
12- import { da } from '@faker-js/faker' ;
1312
1413type OrderByCondition = Record < string , 'ASC' | 'DESC' > ;
1514
@@ -250,7 +249,6 @@ export async function getAll<E extends Entity>(
250249 ) ;
251250 }
252251 const resultData = await resultQuery . getMany ( ) ;
253- console . log ( resultData ) ;
254252 const { included, data } =
255253 this . transformDataService . transformData ( resultData ) ;
256254 return {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export type ExtractNestType<ArrayType> =
2020export interface ConfigParam {
2121 requiredSelectField : boolean ;
2222 debug : boolean ;
23+ useSoftDelete : boolean ;
2324 pipeForId : PipeMixin ;
2425 operationUrl ?: string ;
2526 overrideRoute ?: string ;
You can’t perform that action at this time.
0 commit comments