Currently, I am using typescript alongside prisma and typegraphql in my project. However, I have encountered a type error while working with RatesWhereUniqueInput generated by prisma. This input is classified as a "CompoundUniqueInput" due to the database I am referencing having two keys: clientId (string) and employeeId (number).
My issue arises when trying to utilize both clientId and employeeId in my repository to target a specific database entry using the "update()" method. The problem stems from the type being autogenerated within the prisma client as clientId_employeeId?, leading to a type error.
Repository Function:
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);
}
Prisma index.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,
});
}
}