fix: invite user to the system.

fix: soft delete system user.
This commit is contained in:
a.bouhuolia
2021-01-19 13:18:48 +02:00
parent ef53b25c18
commit 59f44d9ef6
17 changed files with 320 additions and 136 deletions

View File

@@ -4,8 +4,8 @@ exports.up = function (knex) {
table.increments();
table.string('first_name');
table.string('last_name');
table.string('email').unique().index();
table.string('phone_number').unique().index();
table.string('email').index();
table.string('phone_number').index();
table.string('password');
table.boolean('active').index();
table.string('language');

View File

@@ -1,14 +1,9 @@
import { Model, mixin } from 'objection';
import { Model } from 'objection';
import bcrypt from 'bcryptjs';
import SoftDelete from 'objection-soft-delete';
import SystemModel from 'system/models/SystemModel';
import moment from 'moment';
import SoftDeleteQueryBuilder from 'collection/SoftDeleteQueryBuilder';
export default class SystemUser extends mixin(SystemModel, [SoftDelete({
columnName: 'deleted_at',
deletedValue: moment().format('YYYY-MM-DD HH:mm:ss'),
notDeletedValue: null,
})]) {
export default class SystemUser extends SystemModel {
/**
* Table name.
*/
@@ -16,6 +11,13 @@ export default class SystemUser extends mixin(SystemModel, [SoftDelete({
return 'users';
}
/**
* Soft delete query builder.
*/
static get QueryBuilder() {
return SoftDeleteQueryBuilder;
}
/**
* Timestamps columns.
*/
@@ -23,10 +25,16 @@ export default class SystemUser extends mixin(SystemModel, [SoftDelete({
return ['createdAt', 'updatedAt'];
}
/**
* Virtual attributes.
*/
static get virtualAttributes() {
return ['fullName'];
}
/**
* Full name attribute.
*/
get fullName() {
return (this.firstName + ' ' + this.lastName).trim();
}

View File

@@ -22,7 +22,6 @@ export default class SystemUserRepository extends SystemRepository {
return this.cache.get(cacheKey, () => {
return this.model.query()
.whereNotDeleted()
.findOne('email', crediential)
.orWhere('phone_number', crediential);
});
@@ -39,7 +38,6 @@ export default class SystemUserRepository extends SystemRepository {
return this.cache.get(cacheKey, () => {
return this.model.query()
.whereNotDeleted()
.findOne({ id: userId, tenant_id: tenantId });
});
}
@@ -53,7 +51,7 @@ export default class SystemUserRepository extends SystemRepository {
const cacheKey = this.getCacheKey('findOneByEmail', email);
return this.cache.get(cacheKey, () => {
return this.model.query().whereNotDeleted().findOne('email', email);
return this.model.query().findOne('email', email);
});
}
@@ -67,7 +65,6 @@ export default class SystemUserRepository extends SystemRepository {
return this.cache.get(cacheKey, () => {
return this.model.query()
.whereNotDeleted()
.findOne('phoneNumber', phoneNumber);
});
}