Browse Source

refactor: proper request type in controllers

pull/6914/head
Pranav C 1 year ago
parent
commit
256a88118d
  1. 19
      packages/nocodb/src/controllers/auth/auth.controller.ts
  2. 2
      packages/nocodb/src/controllers/forms.controller.ts
  3. 1
      packages/nocodb/src/controllers/galleries.controller.ts
  4. 3
      packages/nocodb/src/controllers/hooks.controller.ts
  5. 1
      packages/nocodb/src/controllers/kanbans.controller.ts
  6. 1
      packages/nocodb/src/controllers/maps.controller.ts
  7. 9
      packages/nocodb/src/controllers/notifications.controller.ts
  8. 7
      packages/nocodb/src/controllers/org-tokens.controller.ts
  9. 9
      packages/nocodb/src/controllers/org-users.controller.ts
  10. 3
      packages/nocodb/src/controllers/public-metas.controller.ts
  11. 9
      packages/nocodb/src/controllers/shared-bases.controller.ts
  12. 5
      packages/nocodb/src/controllers/utils.controller.ts
  13. 9
      packages/nocodb/src/controllers/views.controller.ts
  14. 9
      packages/nocodb/src/modules/jobs/jobs.controller.ts
  15. 5
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.controller.ts
  16. 3
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts
  17. 3
      packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.controller.ts
  18. 1
      packages/nocodb/src/modules/jobs/jobs/source-delete/source-delete.controller.ts
  19. 7
      packages/nocodb/src/types/express.d.ts

19
packages/nocodb/src/controllers/auth/auth.controller.ts

@ -5,10 +5,11 @@ import {
HttpCode,
Param,
Post,
Request,
Response,
Req,
Res,
UseGuards,
} from '@nestjs/common';
import { Request, Response } from 'express';
import { AuthGuard } from '@nestjs/passport';
import { ConfigService } from '@nestjs/config';
import { extractRolesObj } from 'nocodb-sdk';
@ -41,7 +42,7 @@ export class AuthController {
])
@UseGuards(PublicApiLimiterGuard)
@HttpCode(200)
async signup(@Req() req: Request, @Response() res: any): Promise<any> {
async signup(@Req() req: Request, @Res() res:Response): Promise<any> {
if (this.config.get('auth', { infer: true }).disableEmailAuth) {
NcError.forbidden('Email authentication is disabled');
}
@ -61,7 +62,7 @@ export class AuthController {
])
@UseGuards(PublicApiLimiterGuard)
@HttpCode(200)
async refreshToken(@Req() req: Request, @Response() res: any): Promise<any> {
async refreshToken(@Req() req: Request, @Res() res:Response): Promise<any> {
res.json(
await this.usersService.refreshToken({
body: req.body,
@ -78,7 +79,7 @@ export class AuthController {
])
@UseGuards(PublicApiLimiterGuard, AuthGuard('local'))
@HttpCode(200)
async signin(@Request() req, @Response() res) {
async signin(@Req() req:Request, @Res() res:Response) {
if (this.config.get('auth', { infer: true }).disableEmailAuth) {
NcError.forbidden('Email authentication is disabled');
}
@ -89,7 +90,7 @@ export class AuthController {
@UseGuards(GlobalGuard)
@Post('/api/v1/auth/user/signout')
@HttpCode(200)
async signOut(@Request() req, @Response() res): Promise<any> {
async signOut(@Req() req:Request, @Res() res:Response): Promise<any> {
if (!(req as any).isAuthenticated()) {
NcError.forbidden('Not allowed');
}
@ -104,7 +105,7 @@ export class AuthController {
@Post(`/auth/google/genTokenByCode`)
@HttpCode(200)
@UseGuards(PublicApiLimiterGuard, AuthGuard('google'))
async googleSignin(@Request() req, @Response() res) {
async googleSignin(@Req() req:Request, @Res() res:Response) {
await this.setRefreshToken({ req, res });
res.json(await this.usersService.login(req.user, req));
}
@ -117,7 +118,7 @@ export class AuthController {
@Get(['/auth/user/me', '/api/v1/db/auth/user/me', '/api/v1/auth/user/me'])
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
async me(@Request() req) {
async me(@Req() req:Request) {
const user = {
...req.user,
roles: extractRolesObj(req.user.roles),
@ -228,7 +229,7 @@ export class AuthController {
@UseGuards(PublicApiLimiterGuard)
async renderPasswordReset(
@Req() req: Request,
@Response() res: any,
@Res() res:Response,
@Param('tokenId') tokenId: string,
): Promise<any> {
try {

2
packages/nocodb/src/controllers/forms.controller.ts

@ -7,9 +7,9 @@ import {
Patch,
Post,
Req,
Request,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { ViewCreateReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { FormsService } from '~/services/forms.service';

1
packages/nocodb/src/controllers/galleries.controller.ts

@ -9,6 +9,7 @@ import {
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { GalleryUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { GalleriesService } from '~/services/galleries.service';

3
packages/nocodb/src/controllers/hooks.controller.ts

@ -7,9 +7,10 @@ import {
Param,
Patch,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { HookReqType, HookTestReqType } from 'nocodb-sdk';
import type { HookType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';

1
packages/nocodb/src/controllers/kanbans.controller.ts

@ -9,6 +9,7 @@ import {
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { ViewCreateReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { KanbansService } from '~/services/kanbans.service';

1
packages/nocodb/src/controllers/maps.controller.ts

@ -9,6 +9,7 @@ import {
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { MapUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { MapsService } from '~/services/maps.service';

9
packages/nocodb/src/controllers/notifications.controller.ts

@ -7,9 +7,10 @@ import {
Param,
Patch,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { NotificationsService } from '~/services/notifications.service';
import { GlobalGuard } from '~/guards/global/global.guard';
import { extractProps } from '~/helpers/extractProps';
@ -36,7 +37,7 @@ export class NotificationsController {
async notificationUpdate(
@Param('notificationId') notificationId,
@Body() body,
@Request() req,
@Req() req:Request,
) {
return this.notificationsService.notificationUpdate({
notificationId,
@ -47,7 +48,7 @@ export class NotificationsController {
@Post('/api/v1/notifications/mark-all-read')
@HttpCode(200)
async markAllRead(@Request() req) {
async markAllRead(@Req() req:Request) {
return this.notificationsService.markAllRead({
user: req.user,
});
@ -57,7 +58,7 @@ export class NotificationsController {
// @Acl('notificationDelete')
async notificationDelete(
@Param('notificationId') notificationId,
@Request() req,
@Req() req:Request,
) {
return this.notificationsService.notificationUpdate({
notificationId,

7
packages/nocodb/src/controllers/org-tokens.controller.ts

@ -6,9 +6,10 @@ import {
HttpCode,
Param,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { ApiTokenReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import { getConditionalHandler } from '~/helpers/getHandler';
@ -46,7 +47,7 @@ export class OrgTokensController {
scope: 'org',
blockApiTokenAccess: true,
})
async apiTokenCreate(@Request() req, @Body() body: ApiTokenReqType) {
async apiTokenCreate(@Req() req:Request, @Body() body: ApiTokenReqType) {
return await this.orgTokensService.apiTokenCreate({
apiToken: body,
user: req['user'],
@ -60,7 +61,7 @@ export class OrgTokensController {
// allowedRoles: [OrgUserRoles.SUPER],
blockApiTokenAccess: true,
})
async apiTokenDelete(@Request() req, @Param('token') token: string) {
async apiTokenDelete(@Req() req:Request, @Param('token') token: string) {
await this.orgTokensService.apiTokenDelete({
token,
user: req['user'],

9
packages/nocodb/src/controllers/org-users.controller.ts

@ -7,9 +7,10 @@ import {
Param,
Patch,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { OrgUserRoles } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { PagedResponseImpl } from '~/helpers/PagedResponse';
@ -75,7 +76,7 @@ export class OrgUsersController {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
})
async userAdd(@Body() body, @Request() req) {
async userAdd(@Body() body, @Req() req: Request) {
const result = await this.orgUsersService.userAdd({
user: req.body,
req,
@ -104,7 +105,7 @@ export class OrgUsersController {
blockApiTokenAccess: true,
})
async userInviteResend(
@Request() req,
@Req() req: Request,
@Param('userId') userId: string,
): Promise<any> {
await this.orgUsersService.userInviteResend({
@ -122,7 +123,7 @@ export class OrgUsersController {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
})
async generateResetUrl(@Request() req, @Param('userId') userId: string) {
async generateResetUrl(@Req() req: Request, @Param('userId') userId: string) {
const result = await this.orgUsersService.generateResetUrl({
siteUrl: req.ncSiteUrl,
userId,

3
packages/nocodb/src/controllers/public-metas.controller.ts

@ -1,4 +1,5 @@
import { Controller, Get, Param, Request, UseGuards } from '@nestjs/common';
import { Controller, Get, Param, Req, UseGuards } from '@nestjs/common';
import { Request } from 'express';
import { PublicMetasService } from '~/services/public-metas.service';
import { PublicApiLimiterGuard } from '~/guards/public-api-limiter.guard';

9
packages/nocodb/src/controllers/shared-bases.controller.ts

@ -7,9 +7,10 @@ import {
Param,
Patch,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { GlobalGuard } from '~/guards/global/global.guard';
import { SharedBasesService } from '~/services/shared-bases.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
@ -27,7 +28,7 @@ export class SharedBasesController {
@HttpCode(200)
@Acl('createSharedBaseLink')
async createSharedBaseLink(
@Request() req,
@Req() req:Request,
@Body() body: any,
@Param('baseId') baseId: string,
): Promise<any> {
@ -48,7 +49,7 @@ export class SharedBasesController {
])
@Acl('updateSharedBaseLink')
async updateSharedBaseLink(
@Request() req,
@Req() req:Request,
@Body() body: any,
@Param('baseId') baseId: string,
): Promise<any> {
@ -86,7 +87,7 @@ export class SharedBasesController {
])
@Acl('getSharedBaseLink')
async getSharedBaseLink(
@Request() req,
@Req() req:Request,
@Param('baseId') baseId: string,
): Promise<any> {
const sharedBase = await this.sharedBasesService.getSharedBaseLink({

5
packages/nocodb/src/controllers/utils.controller.ts

@ -6,9 +6,10 @@ import {
Get,
HttpCode,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { GlobalGuard } from '~/guards/global/global.guard';
import { UtilsService } from '~/services/utils.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
@ -48,7 +49,7 @@ export class UtilsController {
scope: 'org',
})
@HttpCode(200)
async testConnection(@Body() body: any, @Request() _req: any) {
async testConnection(@Body() body: any, @Req() _req: Request) {
body.pool = {
min: 0,
max: 1,

9
packages/nocodb/src/controllers/views.controller.ts

@ -8,9 +8,10 @@ import {
Patch,
Post,
Query,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { ViewUpdateReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { GlobalGuard } from '~/guards/global/global.guard';
@ -101,7 +102,7 @@ export class ViewsController {
])
@HttpCode(200)
@Acl('shareView')
async shareView(@Param('viewId') viewId: string, @Request() req) {
async shareView(@Param('viewId') viewId: string, @Req() req:Request) {
return await this.viewsService.shareView({ viewId, user: req.user, req });
}
@ -126,7 +127,7 @@ export class ViewsController {
async shareViewUpdate(
@Param('viewId') viewId: string,
@Body() body: ViewUpdateReqType,
@Request() req,
@Req() req:Request,
) {
return await this.viewsService.shareViewUpdate({
viewId,
@ -141,7 +142,7 @@ export class ViewsController {
'/api/v2/meta/views/:viewId/share',
])
@Acl('shareViewDelete')
async shareViewDelete(@Param('viewId') viewId: string, @Request() req) {
async shareViewDelete(@Param('viewId') viewId: string, @Req() req:Request) {
return await this.viewsService.shareViewDelete({
viewId,
user: req.user,

9
packages/nocodb/src/modules/jobs/jobs.controller.ts

@ -4,10 +4,11 @@ import {
HttpCode,
Inject,
Post,
Request,
Response,
Req,
Res,
UseGuards,
} from '@nestjs/common';
import { Request, Response } from 'express';
import { OnEvent } from '@nestjs/event-emitter';
import { customAlphabet } from 'nanoid';
import { ModuleRef } from '@nestjs/core';
@ -46,7 +47,7 @@ export class JobsController implements OnModuleInit {
@Post('/jobs/listen')
@HttpCode(200)
async listen(
@Response() res,
@Res() res:Response &{resId?:string},
@Req() req: Request,
@Body() body: { _mid: number; data: { id: string } },
) {
@ -134,7 +135,7 @@ export class JobsController implements OnModuleInit {
res.on('close', () => {
if (jobId && this.jobRooms[jobId]?.listeners) {
this.jobRooms[jobId].listeners = this.jobRooms[jobId].listeners.filter(
(r) => r.resId !== res.resId,
(r) => r.resId !== (res as any).resId,
);
}
});

5
packages/nocodb/src/modules/jobs/jobs/at-import/at-import.controller.ts

@ -3,9 +3,10 @@ import {
HttpCode,
Inject,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { GlobalGuard } from '~/guards/global/global.guard';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { SyncSource } from '~/models';
@ -69,7 +70,7 @@ export class AtImportController {
])
@Acl('airtableImport')
@HttpCode(200)
async abortImport(@Request() _) {
async abortImport() {
return {};
}
}

3
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts

@ -5,9 +5,10 @@ import {
Inject,
Param,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { ProjectStatus } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';

3
packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.controller.ts

@ -4,9 +4,10 @@ import {
Inject,
Param,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { GlobalGuard } from '~/guards/global/global.guard';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { NcError } from '~/helpers/catchError';

1
packages/nocodb/src/modules/jobs/jobs/source-delete/source-delete.controller.ts

@ -6,6 +6,7 @@ import {
Req,
UseGuards,
} from '@nestjs/common';
import { Request } from 'express';
import { GlobalGuard } from '~/guards/global/global.guard';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { NcError } from '~/helpers/catchError';

7
packages/nocodb/src/types/express.d.ts vendored

@ -18,9 +18,10 @@ import { Express } from 'express-serve-static-core';
// }
declare module 'express-serve-static-core' {
interface Request {
// id?: string;
// ncWorkspaceId?: string;
// ncProjectId?: string;
ncWorkspaceId?: string;
ncProjectId?: string;
user: any;
ncSiteUrl: string;
clientIp: string;
}
}

Loading…
Cancel
Save