@random-guys/rented-bucket
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @random-guys/rented-bucket

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

13.7 kB

Total Files

15

Last publish

Collaborators

  • random-guys