Skip to content

Commit 62424b8

Browse files
committed
fix: #19 fix ts and deprecation problems
1 parent 4d80b47 commit 62424b8

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

api/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AppController } from './../controllers/app.controller';
12
import { Module, Scope } from '@nestjs/common';
23
import { AuthController } from '../controllers/auth/auth.controller';
34
import { UserController } from '../controllers/user/user.controller';
@@ -18,6 +19,7 @@ import { DatabaseService } from '../services/database/database.service';
1819
}),
1920
AuthController,
2021
UserController,
22+
AppController,
2123
],
2224
providers: [
2325
{

api/src/core/controller.core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ export const getRequestUser = (data: unknown, ctx: ExecutionContext) => {
6969
};
7070
export const User = createParamDecorator(getRequestUser);
7171

72-
export function mapResponse<T, EI, EO>(data: T | BaseError<EI>) {
72+
export function mapResponse<T, EI extends BaseError<unknown>, EO>(data: T | EI) {
7373
return async (
74-
onData: (data: T) => ControllerResponse | Promise<ControllerResponse>,
75-
onError?: (e: BaseError<EI>) => BaseError<EO> | Promise<BaseError<EO>>,
74+
onData: (data: Exclude<T, EI>) => ControllerResponse | Promise<ControllerResponse>,
75+
onError?: (e: EI) => BaseError<EO> | Promise<BaseError<EO>>,
7676
) =>
7777
isError(data)
7878
? onError
7979
? Promise.resolve(onError(data))
8080
: Promise.resolve(data)
81-
: Promise.resolve(onData(data));
81+
: Promise.resolve(onData(data as Exclude<T, EI>));
8282
}

api/src/core/interceptor.core.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
OnModuleInit,
1111
} from '@nestjs/common';
1212
import { RequestContext } from '@medibloc/nestjs-request-context';
13-
import { from, Observable } from 'rxjs';
13+
import { from, lastValueFrom, Observable } from 'rxjs';
1414
import { catchError, map, mergeMap } from 'rxjs/operators';
1515
import { ControllerResponse } from './controller.core';
1616
import { TransactionsContext } from '../utils/transactions.utils';
@@ -47,9 +47,8 @@ export class HttpInterceptor implements NestInterceptor, OnModuleInit {
4747
this.db.Prisma.$transaction(
4848
async (prisma) => {
4949
await ctx.transactions.init(prisma);
50-
return next
51-
.handle()
52-
.pipe(
50+
return lastValueFrom(
51+
next.handle().pipe(
5352
mergeMap(async (data) => {
5453
if (data instanceof ControllerResponse) {
5554
return data;
@@ -75,8 +74,8 @@ export class HttpInterceptor implements NestInterceptor, OnModuleInit {
7574
'or a BaseError<string>',
7675
);
7776
}),
78-
)
79-
.toPromise();
77+
),
78+
);
8079
},
8180
{ maxWait: 20000, timeout: 50000 },
8281
),
@@ -142,7 +141,7 @@ export class HttpInterceptor implements NestInterceptor, OnModuleInit {
142141
if (process.env['TEST'] !== 'true') {
143142
response.send(
144143
`${R.omit(['stack'], body)}\nStack: ${
145-
process.env['FULL_PRODUCTION_MODE'] !== 'true' ? body?.stack : ''
144+
process.env['ENVIRONMENT'] !== 'prod' ? body?.stack : ''
146145
}`,
147146
);
148147
} else {

api/src/services/config/config.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ConfigServiceProvider implements ConfigDto {
2828
const devEnvPath = path.join(process.cwd(), `env/dev.env`);
2929
const env: Partial<ConfigDto> = isDev
3030
? dotenv.parse(fs.readFileSync(devEnvPath))
31-
: process.env;
31+
: (process.env as Partial<ConfigDto>);
3232

3333
const envValidation = validateSync(ConfigDto, env);
3434
if (envValidation.status === 'fail') {

api/src/services/database/database.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class DatabaseServiceProvider {
4343
}
4444

4545
@Module({
46-
imports: [ConfigService, Logger],
46+
imports: [ConfigService],
4747
providers: [DatabaseServiceProvider],
4848
exports: [DatabaseServiceProvider],
4949
})

api/src/utils/validation.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function validate<C>(
3535
options?: ValidatorOptions,
3636
): Promise<ValidationSuccess<C> | ValidationFail> {
3737
const value = plainToClass(SchemeClass, data);
38-
return classValidate(value, options).then((errors) =>
38+
return classValidate(value as Record<string, unknown>, options).then((errors) =>
3939
errors.length > 0 ? { errors, status: 'fail' } : { value, status: 'success' },
4040
);
4141
}
@@ -46,7 +46,7 @@ export function validateSync<C>(
4646
options?: ValidatorOptions,
4747
): ValidationSuccess<C> | ValidationFail {
4848
const value = plainToClass(SchemeClass, data);
49-
const errors = classValidateSync(value, options);
49+
const errors = classValidateSync(value as Record<string, unknown>, options);
5050
return errors.length > 0 ? { errors, status: 'fail' } : { value, status: 'success' };
5151
}
5252

0 commit comments

Comments
 (0)