【发布时间】:2021-09-27 09:05:30
【问题描述】:
我正在使用带有 prisma 和 typegraphql 的 typescript 并收到此类型错误。 RatesWhereUniqeInput 由 prisma 生成,并将自身定义为“CompoundUniqueInput”,因为我引用的数据库有 2 个键(clientId:string,employeeId:number)。
在我的存储库中,我想同时使用这两种方法来使用“update()”来引用特定的数据库行,但是因为类型是在 prisma 客户端中生成的 clientId_employeeId?我收到类型错误。
存储库函数
async update(model: Rates): Promise<Rates> {
const { employeeId, clientId, ...data } = this.mapper.from(model);
const entity = await this.db.rates.update({
where: { employeeId, clientId },
data: {
...data,
},
});
return this.mapper.to(entity);
}
棱镜索引.d.ts
export type RatesWhereUniqueInput = {
clientId_employeeId?: RatesClientIdEmployeeIdCompoundUniqueInput
}
ratesmapper.ts
@injectable()
export class RatesMapper {
public from(model: Rates): RatesEntity {
return {
employeeId: model.employeeId,
clientId: model.clientId,
rateFull: model.rateFull,
rateQuarter: model.rateQuarter,
rateLine: model.rateLine,
rateWord: model.rateWord,
createdAt: model.createdAt,
updatedAt: model.updatedAt,
};
}
public to(entity: RatesEntity): Rates {
return new Rates({
...entity,
});
}
}
【问题讨论】:
标签: typescript apollo prisma typegraphql