@random-guys/rented-bucket
v0.1.0
Published
Wrapper around axios for interservice communication
Downloads
4
Readme
rented-bucket
A repo to use when working with a multi-tenant products.
Why
Sometimes you have objects that cannot be stored without an external ID, a foreign key if you will. Everything that you'll do, read, write, update will be done based on this ID. You under no circumstances want to query those objects based solely on their own properties. This package helps you enforce it in your repo methods.
How to install?
yarn add @random-guys/rented-bucket
How does it work?
// create base model
export interface SchoolModel extends Model {
school: string
}
// base repo
export class SchoolRepository<T extends SchoolModel> extends RentedRepository<T> {
constructor(mongoose: MongooseNamespace,name: string, schema: Schema) {
super(mongoose, name, 'school', schema)
}
}
// use the model
export interface Student extends SchoolModel {
full_name: string
class: string
age: number
average_grade: number
}
export class SchoolRepository extends SchoolRepository<Student> {
constructor(mongoose: MongooseNamespace) {
super(mongoose, 'Student', RoleSchema)
}
// live with it
getIdiots(school: string) {
return this.all({
conditions: {
average_grade: { $lte: 4.0 }
}
})
}
}
export const StudentSchema = RentedSchema('school', {
class: { ...trimmedString, required: true },
full_name: { ...trimmedString, required: true, unique: true, index: true },
// figure out the rest, I'm tired of writing
})
TODO
[ ] Tests