Re-init DB and scaffold all models
This commit is contained in:
13
api/src/services/helpers.js
Normal file
13
api/src/services/helpers.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export const foreignKeyReplacement = (input) => {
|
||||
let output = input
|
||||
const foreignKeys = Object.keys(input).filter((k) => k.match(/Id$/))
|
||||
foreignKeys.forEach((key) => {
|
||||
const modelName = key.replace(/Id$/, '')
|
||||
const value = input[key]
|
||||
delete output[key]
|
||||
output = Object.assign(output, {
|
||||
[modelName]: { connect: { id: value } },
|
||||
})
|
||||
})
|
||||
return output
|
||||
}
|
||||
Reference in New Issue
Block a user