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 {
Body,
Controller,
Get,
HttpCode,
Param,
Post,
Patch,
Request,
Response,
UseGuards,
@ -12,6 +10,7 @@ import {
import { ConfigService } from '@nestjs/config';
import type { AppConfig } from '~/interface/config';
import { GlobalGuard } from '~/guards/global/global.guard';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { UsersService } from '~/services/users/users.service';
@ -23,4 +22,16 @@ export class UsersController {
protected readonly appHooksService: AppHooksService,
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;
token_version?: string;
display_name?: string;
avatar?: string;
constructor(data: User) {
Object.assign(this, data);
}
@ -80,6 +83,8 @@ export default class User implements UserType {
'email_verified',
'roles',
'token_version',
'display_name',
'avatar',
]);
if (updateObj.email) {

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

@ -64,6 +64,30 @@
}
],
"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": {
"post": {
"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 { NcError } from '~/helpers/catchError';
import { ProjectsService } from '~/services/projects.service';
import { extractProps } from '~/helpers/extractProps';
@Injectable()
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({
email,
salt,

Loading…
Cancel
Save