@secjs/base
v1.2.8
Published
> Base stuffs for any NodeJS project
Downloads
7
Readme
Base 📐
Base stuffs for any NodeJS project
The intention behind this repository is to always maintain a Base
project to any NodeJS project.
Installation
To use the high potential from this package you need to install first this other packages from SecJS, it keeps as dev dependency because one day
@secjs/core
will install everything once.
npm install @secjs/contracts @secjs/exceptions @secjs/utils
Then you can install the package using:
npm install @secjs/base
BaseService
Use to get nice methods to use with @secjs/base repositories
import { User } from 'app/Models/User'
import { NotFoundException } from '@nestjs/common'
import { BaseService } from '@secjs/base/services/BaseService'
import { ContactResource } from 'app/Resources/ContactResource'
import { ContactRepository } from 'app/Repositories/ContactRepository'
class ContactService extends BaseService<User> {
protected resourceName = 'contact'
protected resource = new ContactResource()
protected repository = new ContactRepository()
protected NotFoundException: any = NotFoundException // Define exception or use NotFoundException default from @secjs/exceptions
// You can subscribe BaseService methods in here if you want!
}
LucidRepository
Use LucidRepository to get nice methods based on ApiRequestContract
import { User } from 'app/Models/User'
import { LucidRepository } from '@secjs/base/repositories/LucidRepository'
class UserRepository extends LucidRepository<User> {
model = User // Give the Model value to Lucid, so he knows what to work with.
wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client
// Both, wheres and relations will only work for external requests.
// You can subscribe LucidRepository methods in here if you want!
}
TypeOrmRepository
Use TypeOrmRepository to get nice methods based on ApiRequestContract
import { User } from 'app/Models/User'
import { TypeOrmRepository } from '@secjs/base/repositories/TypeOrmRepository'
class UserRepository extends TypeOrmRepository<User> {
model = User // Give the Model value to Lucid, so he knows what to work with.
wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client
// Both, wheres and relations will only work for external requests.
// You can subscribe TypeOrmRepository methods in here if you want!
}
MongooseRepository
Use MongooseRepository to get nice methods based on ApiRequestContract
import { User, UserDocument } from 'app/Schemas/User'
import { MongooseRepository } from '@secjs/base/repositories/MongooseRepository'
class UserRepository extends MongooseRepository<UserDocument> {
model = User // Give the Model value to Mongoose, so he knows what to work with.
wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client
// Both, wheres and relations will only work for external requests.
// You can subscribe MongooseRepository methods in here if you want!
}
PrismaRepository
Use PrismaRepository to get nice methods based on ApiRequestContract
import { User } from 'app/Models/User'
import { PrismaRepository } from '@secjs/base/repositories/PrismaRepository'
class UserRepository extends PrismaRepository<User> {
model = User // Give the Model value to Lucid, so he knows what to work with.
wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client
// Both, wheres and relations will only work for external requests.
// You can subscribe PrismaRepository methods in here if you want!
}
License
Made with 🖤 by jlenon7 :wave: