Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
UserService,
} from '@loopback/authentication';
import {inject} from '@loopback/core';
import {get, post, requestBody} from '@loopback/rest';
import {get, post, requestBody, getModelSchemaRef} from '@loopback/rest';
import {SecurityBindings, securityId, UserProfile} from '@loopback/security';
import {TokenServiceBindings, User, UserServiceBindings} from '../../../';
import {Credentials} from '../../../services/user.service';
Expand Down Expand Up @@ -95,4 +95,39 @@ export class UserController {
async whoAmI(): Promise<string> {
return this.user[securityId];
}
@post('/signup', {
responses: {
'200': {
description: 'User',
content: {
'application/json': {
schema: {
'x-ts-type': User,
},
},
},
},
},
})
async signUp(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(NewUserRequest, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No definition for NewUserRequest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title: 'NewUser',
}),
},
},
})
newUserRequest: NewUserRequest,
): Promise<User> {
const password = await hash(newUserRequest.password, await genSalt());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No definition for hash and gen salt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const savedUser = await this.userRepository.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will throw a property does not exist. as no dependency injection.

_.omit(newUserRequest, 'password'),
);

await this.userRepository.userCredentials(savedUser.id).create({password});

return savedUser;
}
}