I am currently working on implementing an API using express, objection.js, and TypeScript.
I found a lot of inspiration from this repository: https://github.com/HappyZombies/brackette-alpha/tree/master/server/src
Similar to the creator, I aim to have various interfaces for the same "component" (e.g., user).
In examining his approach, he has created different interfaces (here) and utilizes them in his services as a returned promise (here). However, there is no verification that what he returns matches his interface. To align with his promised interface, he only selects SQL fields that match his interface.
public async findAll(): Promise<IUserMiminimum[]> {
let users;
try {
users = await this.usersModel.query().column('username', 'displayName');
} catch (err) {
this.logger.error(err);
throw err;
}
return users;
}
My queries are:
- Is there a method to solely choose the desired fields from the model results based on the interface description?
- Alternatively, is there a way to validate that the interface aligns with the model outcomes?
Thank you for taking the time to read.