我想出的第一件事是调用computedInputs
选项nexusPrisma
。但这行不通,因为它们需要根据情况进行不同的处理,但在全球范围内:
1. create -> createdAt = now, updatedAt = null
2. update -> createdAt = keep as it is, updatedAt = now
为了使它工作,我需要像这样单独设置 computedInputs:
t.crud.createOneX({
computedInputs: {
createdAt: () => DateTime.utc().toString(),
updatedAt: () => null,
},
});
t.crud.updateOneX({
computedInputs: {
createdAt: () => undefined,
updatedAt: () => DateTime.utc().toString(),
},
});
虽然这可能有效,但我无法在嵌套模型上“计算”这些输入。为了防止传递 createdAt/updatedAt,我还必须t.crud
在该资源上创建另一个,没有这些时间戳。
可能有效的最后一个解决方法是根本不使用t.crud
,这是一个无赖。