0.4.0 • Published 12 months ago

@goodrequest/user-repository-sequelize v0.4.0

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Build and run tests Publish package to GitHub Packages

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:

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
}
0.3.0

1 year ago

0.4.0

12 months ago

0.2.0

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.1

1 year ago