adminjs-prisma
adminjs-prisma copied to clipboard
Unhandled type: Bytes
It seems that the prisma adapter does not support the "bytes" type: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#bytes
Console output simply says: Unhandled type: Bytes
I get the same. Any idea how it should behave in the case of Bytes?
Faced with the same problem, but was able to find the temporary solution:
First of all, I i've got such (dot notation) Payload:
{
.....
'password.type': 'Buffer',
'password.data.0': '123',
'password.data.1': '21',
'password.data.2': '146',
'password.data.3': '168',
'password.data.4': '174',
.....
}
Into a normal object:
....
{
type: 'Buffer',
data: [
'123', '21', '146', '168', '174',
'142', '68', '50', '105', '91',
'154', '143', '96', '108', '201',
'236', '4', '73', '76', '161',
'109', '120', '172', '212', '161',
'172', '152', '115', '2', '146',
'122', '53'
]
}
....
After that, we take Data from this object and turn it into a Buffer
Buffer.from(payload.password.data)
And after that I reassign this Buffer to the password value in the payload. And yes - it works!
Full code:
options: {
actions: {
edit: {
before: async (request) => {
if (isGETMethod(request)) {
return request;
}
// convert "dot notation" to regular object
let payload: any = {};
for (const key in request.payload) {
_.set(payload, key, _.get(request.payload, key));
}
// convert "password object" to Buffer & assign to payload
_.set(payload, 'password', Buffer.from(payload.password.data));
request.payload = payload;
// return request.payload.password with Buffer type
return request
},
}
}
}
It's my first day using AdminJS and I don't know all the mechanics - if someone can write some more convenient handler for Bytes data based on this, it will be cool.