BennySama
BennySama
MManifest
Created by BennySama on 3/1/2025 in #questions-🙋
Is there a cleaner/more appropriate way to auto-create this entity relationship in the Middleware?
Hello, my current middleware to additionally create a Profile entitiy for the newly registered user looks like this:
module.exports = async (req, res, manifest) => {
const user = await manifest.from('users').where('name = ' + req.body.name).find();
const userId = user.data[0].id;
await manifest.from('profiles').create({
userId: userId,
});
}
module.exports = async (req, res, manifest) => {
const user = await manifest.from('users').where('name = ' + req.body.name).find();
const userId = user.data[0].id;
await manifest.from('profiles').create({
userId: userId,
});
}
Is there a better, or rather, more sanitized way to additionally create the entity like this?
6 replies
MManifest
Created by BennySama on 2/25/2025 in #questions-🙋
API Policies - Custom Policy
It's less of a question, but more of a suggestion I would like to ask here, maybe there is also a solution for it already. If we will get a working "default" option like this example:
entities:
User:
authenticable: true
properties:
- name
- {name: role, type: choice, options: {values: ["admin", "mod", "user"], default: "user"}}
entities:
User:
authenticable: true
properties:
- name
- {name: role, type: choice, options: {values: ["admin", "mod", "user"], default: "user"}}
Wouldn't it be also great to make our own custom policy, where it doesn't necessarily has to depend on the 4 access types? I am going to take the Invoice example to show what I mean
entities:
Invoice 🧾:
properties:
- number
- { name: issueDate, type: date }
policies:
create:
- { access: custom, allow: UserRole ["admin", "mod"] }
update:
- access: admin
delete:
- access: forbidden


policies:
UserRole:
User:
- {property: role, policy: restricted}
entities:
Invoice 🧾:
properties:
- number
- { name: issueDate, type: date }
policies:
create:
- { access: custom, allow: UserRole ["admin", "mod"] }
update:
- access: admin
delete:
- access: forbidden


policies:
UserRole:
User:
- {property: role, policy: restricted}
I hope that's understandable enough, but if there are more ideas or question, I'll be happy to answer them
3 replies