I need some help. I create User entity by using typeorm and I want to overwrite toResponseObject at Customer class for change return attribute but when I write finished the error occurs as "Type '{ userName: string; firstName: string; lastName: string; email: string; address: Address; token: string; }' is missing the following properties from type 'User': password, hasPassword, toResponObject, comparePassword" I guess this means I should return all of User Property but I don't want to return all of the attributes. What should I do?
user.entity.ts
import {PrimaryColumn, Column, BeforeInsert} from "typeorm";
import * as bcrypt from 'bcryptjs'
import * as jwt from 'jsonwebtoken'
export abstract class User {
@PrimaryColumn()
userName: string;
@Column()
password: string;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
email: string;
@BeforeInsert()
async hasPassword(){
this.password = await bcrypt.hash(this.password,10)
}
async toResponObject(showToken:boolean = true){
const {userName,firstName,lastName,email,token} = this
const responseObject = {userName,firstName,lastName,email,token}
if(showToken){
responseObject.token = token
}
return responseObject
}
async comparePassword(attemp:string){
return await bcrypt.compare(attemp,this.password)
}
protected get token(){
const {userName,password} = this
return jwt.sign({userName,password},process.env.SECRETKEY,{expiresIn:'7d'})
}
}
customer.entity.ts
import { Pet } from "../pet/pet.entity";
import { Address } from "../address/address.entity";
import { Order } from "../order/order.entity";
import { Feedback } from "../feedback/feedback.entity";
import { User } from "../user/user.entity";
import { Entity, Column, ManyToOne, OneToMany } from "typeorm";
@Entity()
export class Customer extends User {
@Column()
phoneNumber: string;
@OneToMany(type => Pet,pet => pet.owner)
pets: Pet[];
@ManyToOne(type => Address)
address: Address;
@OneToMany(type => Order,order => order.customer)
orders: Order[];
@OneToMany(type => Feedback,feedbacks => feedbacks.customer)
feedbacks: Feedback[];
async toResponObject(showToken:boolean = true):Promise<User>{
const {userName,firstName,lastName,email,address,token} = this
const responseObject = {userName,firstName,lastName,email,address,token}
if(showToken){
responseObject.token = token
}
return responseObject // error ocuurs at this line
}
}