company.entity.ts
@Schema({
timestamps: true,
versionKey: false,
})
export class Company {
@Prop({ type: String, trim: true, required: true })
name: string;
@Prop({ type: String, trim: true, required: true })
address: string;
@Prop({ type: Boolean, required: true, default: false })
isDeleted: boolean;
@Prop({
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User',
})
createdBy: () => User;
}
export const CompanySchema = SchemaFactory.createForClass(Company);
字符串
user.schema.ts
@Schema({
timestamps: true,
versionKey: false,
})
export class User {
@Prop({
type: mongoose.Schema.Types.ObjectId,
ref: 'Company',
required: true,
})
companyId: () => Company;
@Prop({ type: String, trim: true, required: true })
firstName: string;
@Prop({ type: String, trim: true, required: true })
lastName: string;
@Prop({ type: String, trim: true, required: true, unique: true })
email: string;
@Prop({ type: String, trim: true })
password: string;
@Prop({ type: Boolean, required: true, default: false })
isDeleted: boolean;
}
export const UserSchema = SchemaFactory.createForClass(User);
型
现在,当我试图访问嵌套的属性,我从用户数据使用findOne
。
const user = await this.userModel
.findOne(
{ _id: payload.id, isDeleted: false, isActive: true },
)
.populate('companyId')
.lean();
if (user.companyId.isDeleted && user.companyId.isDeleted === false)
throw new UnauthorizedException(CONSTANT.NOT_FOUND('User'));
型
它给予我一个 typescript 错误,
类型“()=> Company”上不存在属性“”islogic“。
我如何解决这个typescript问题。
1条答案
按热度按时间qmelpv7a1#
你试过
@Prop({ type: Boolean, required: true, default: false }) public isDeleted: boolean;
吗