@goodrequest/user-repository-sequelize
v0.4.0
Published
[![Build and run tests](https://github.com/GoodRequest/user-repository-sequelize/actions/workflows/build.yaml/badge.svg)](https://github.com/GoodRequest/user-repository-sequelize/actions/workflows/build.yaml) [![Publish package to GitHub Packages](https:/
Downloads
4
Readme
User Repository implemented using Sequelize
This is implementation of user repository interface specified in passport-jwt-wrapper library. It uses sequelize library for the data storage.
Installation
npm i --save @goodrequest/user-repository-sequelize
Usage
import { UserRepository } from '@goodrequest/user-repository-sequelize'
import { models } from './db/models'
initAuth(passport, {
userRepository: new UserRepository(models.User),
refreshTokenRepository
})
Models Templates
Library also exports basic Sequelize models:
BaseUserModel
: BaseUserModel -id
is not defined in the attributes, needs to expandedUUIDUserModel
: UUIDUserModel - Usesuuid
asid
BigIntUserModel
: BigIntUserModel- UsesBIGINT
with autoincrement asid
Model definition is divided into:
UserModelClass
UserModelAttributes
UserModelOptions
These parts are used in the sequelize init
method:
UserModel.init(UserModelAttributes, UserModelOptions)
Model needs to be defined and can be expanded using these parts. Examples are in the tests folder:
export class UuidUserModel extends UUIDUserModel {}
/* eslint-disable no-param-reassign */
export default (sequelize: Sequelize, modelName: string) => {
UuidUserModel.init(
{
...UUIDUserModelAttributes,
// overload createdBy column definition
createdBy: {
type: DataTypes.UUID,
allowNull: true
},
// virtual attributes
fullName: {
type: DataTypes.VIRTUAL,
get() {
return `${this.name ?? ''} ${this.surname ?? ''}`.trim()
}
}
},
{
...UUIDUserModelOptions,
sequelize,
modelName,
tableName: 'uuid-users'
}
)
return UuidUserModel
}