Browse Source

fix(nocohub): Added profile update api and also to swagger

pull/6376/head
Muhammed Mustafa 1 year ago
parent
commit
85dfe7faf4
  1. 17
      packages/nocodb/src/controllers/users/users.controller.ts
  2. 5
      packages/nocodb/src/models/User.ts
  3. 24
      packages/nocodb/src/schema/swagger.json
  4. 16
      packages/nocodb/src/services/users/users.service.ts

17
packages/nocodb/src/controllers/users/users.controller.ts

@ -1,10 +1,8 @@
import { import {
Body, Body,
Controller, Controller,
Get,
HttpCode, HttpCode,
Param, Patch,
Post,
Request, Request,
Response, Response,
UseGuards, UseGuards,
@ -12,6 +10,7 @@ import {
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import type { AppConfig } from '~/interface/config'; import type { AppConfig } from '~/interface/config';
import { GlobalGuard } from '~/guards/global/global.guard';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { UsersService } from '~/services/users/users.service'; import { UsersService } from '~/services/users/users.service';
@ -23,4 +22,16 @@ export class UsersController {
protected readonly appHooksService: AppHooksService, protected readonly appHooksService: AppHooksService,
protected readonly config: ConfigService<AppConfig>, protected readonly config: ConfigService<AppConfig>,
) {} ) {}
@Patch(['/api/v1/user/profile'])
@UseGuards(GlobalGuard)
@HttpCode(200)
async update(@Body() body, @Request() req, @Response() res) {
res.json(
await this.usersService.profileUpdate({
id: req.user.id,
params: body,
}),
);
}
} }

5
packages/nocodb/src/models/User.ts

@ -25,6 +25,9 @@ export default class User implements UserType {
roles?: string; roles?: string;
token_version?: string; token_version?: string;
display_name?: string;
avatar?: string;
constructor(data: User) { constructor(data: User) {
Object.assign(this, data); Object.assign(this, data);
} }
@ -80,6 +83,8 @@ export default class User implements UserType {
'email_verified', 'email_verified',
'roles', 'roles',
'token_version', 'token_version',
'display_name',
'avatar',
]); ]);
if (updateObj.email) { if (updateObj.email) {

24
packages/nocodb/src/schema/swagger.json

@ -64,6 +64,30 @@
} }
], ],
"paths": { "paths": {
"/api/v1/user/profile": {
"patch": {
"summary": "Update User Profile",
"operationId": "user-profile-update",
"responses": {
"200": {
"$ref": "#/components/schemas/User"
}
},
"tags": [
"User profile"
],
"description": "Update User Profile",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
},
"/api/v1/auth/user/signup": { "/api/v1/auth/user/signup": {
"post": { "post": {
"summary": "Signup", "summary": "Signup",

16
packages/nocodb/src/services/users/users.service.ts

@ -25,6 +25,7 @@ import { randomTokenString } from '~/helpers/stringHelpers';
import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { ProjectsService } from '~/services/projects.service'; import { ProjectsService } from '~/services/projects.service';
import { extractProps } from '~/helpers/extractProps';
@Injectable() @Injectable()
export class UsersService { export class UsersService {
@ -70,6 +71,21 @@ export class UsersService {
}); });
} }
async profileUpdate({
id,
params,
}: {
id: number;
params: {
display_name?: string;
avatar?: string;
};
}) {
const updateObj = extractProps(params, ['display_name', 'avatar']);
return await User.update(id, updateObj);
}
async registerNewUserIfAllowed({ async registerNewUserIfAllowed({
email, email,
salt, salt,

Loading…
Cancel
Save