-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
needs steps to reproduceIssues missing a small app and/or instructions for reproducing the problemIssues missing a small app and/or instructions for reproducing the problem
Description
src/controllers/ctr-users.controller.ts:78:18 - error TS2345: Argument of type '{ description: string; required: boolean; content: { 'application/json': { schema: { type: string; required: string[]; properties: { login: { type: string; }; password: { type: string; minLength: number; }; }; }; }; }; }' is not assignable to parameter of type 'Partial<RequestBodyObject>'.
Types of property 'content' are incompatible.
Type '{ 'application/json': { schema: { type: string; required: string[]; properties: { login: { type: string; }; password: { type: string; minLength: number; }; }; }; }; }' is not assignable to type 'ContentObject'.
Property ''application/json'' is incompatible with index signature.
Type '{ schema: { type: string; required: string[]; properties: { login: { type: string; }; password: { type: string; minLength: number; }; }; }; }' is not assignable to type 'MediaTypeObject'.
Types of property 'schema' are incompatible.
Type '{ type: string; required: string[]; properties: { login: { type: string; }; password: { type: string; minLength: number; }; }; }' is not assignable to type 'ReferenceObject | SchemaObject | undefined'.
Type '{ type: string; required: string[]; properties: { login: { type: string; }; password: { type: string; minLength: number; }; }; }' is not assignable to type 'SchemaObject'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"string" | "number" | "boolean" | "object" | "integer" | "null" | "array" | undefined'.
78 @requestBody(CredentialsRequestBody) credentials: Credentials,
My controller is
// Uncomment these imports to begin using these cool features!
import { inject } from "@loopback/core";
import { repository } from "@loopback/repository";
import { getJsonSchemaRef, post, requestBody } from "@loopback/rest";
import { TokenServiceBindings, UserServiceBindings } from "../keys";
import { MdlUsers } from "../models";
import { Credentials, MdlUsersRepository } from "../repositories";
import { JWTService } from "../services/jwt-service";
import { MyUserService } from "../services/user-service";
import { CredentialsRequestBody } from "./specs/ctr-users-controller.specs";
// import {inject} from '@loopback/core';
export class CtrUsersController {
constructor(
@repository(MdlUsersRepository) public userRepository: MdlUsersRepository,
@inject(TokenServiceBindings.TOKEN_SERVICE)
public jwtService: JWTService,
@inject(UserServiceBindings.USER_SERVICE)
public userService: MyUserService,
) { }
@post('users/signup', {
responses: {
'200': {
description: 'NewUser',
content: {
'application/json':{
// content: {
/* schema:{
type: 'object',
properties: {
password: {
type: 'string',
},
},
},*/
schema: getJsonSchemaRef(MdlUsers),
},
},
},
},
})
/* async signup(@requestBody() password:string) {
const md5 = require('md5')
var password = 'geeks123'
console.log('Normal password : ', password)
console.log('Hashed password : ', md5(password))
}*/
async signup(@requestBody() user: MdlUsers) {
const md5 = require('md5')
user.password = md5(user.password);
const savedUser = await this.userRepository.create(user);
//delete savedUser.password;
return savedUser;
}
@post('/users/login', {
responses: {
'200': {
description: 'Token',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
token: {
type: 'string',
},
},
},
},
},
},
},
})
async login(
@requestBody(CredentialsRequestBody) credentials: Credentials,
): Promise<{ token: string }> {
// ensure the user exists, and the password is correct
const user = await this.userService.verifyCredentials(credentials);
// convert a User object into a UserProfile object (reduced set of properties)
const userProfile = this.userService.convertToUserProfile(user);
// create a JSON Web Token based on the user profile
const token = await this.jwtService.generateToken(userProfile);
//insert generated token into the database
const update_token = await this.userRepository.updateById(userProfile.id, { token: token })
return { token };
}
}How to solve this error?
Metadata
Metadata
Assignees
Labels
needs steps to reproduceIssues missing a small app and/or instructions for reproducing the problemIssues missing a small app and/or instructions for reproducing the problem