WIP pass the failed tests.

This commit is contained in:
Ahmed Bouhuolia
2020-05-17 07:08:12 +02:00
parent 00de156c9f
commit 10f636d2bc
77 changed files with 2164 additions and 1403 deletions

View File

@@ -7,6 +7,7 @@ import Mustache from 'mustache';
import jwt from 'jsonwebtoken';
import { pick } from 'lodash';
import uniqid from 'uniqid';
import moment from 'moment';
import Logger from '@/services/Logger';
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
import SystemUser from '@/system/models/SystemUser';
@@ -19,6 +20,7 @@ import TenantsManager from '@/system/TenantsManager';
import TenantModel from '@/models/TenantModel';
import PasswordReset from '@/system/models/PasswordReset';
export default {
/**
* Constructor method.
@@ -51,7 +53,7 @@ export default {
login: {
validation: [
check('crediential').exists().isEmail(),
check('password').exists().isLength({ min: 4 }),
check('password').exists().isLength({ min: 5 }),
],
async handler(req, res) {
const validationErrors = validationResult(req);
@@ -87,7 +89,17 @@ export default {
errors: [{ type: 'USER_INACTIVE', code: 110 }],
});
}
// user.update({ last_login_at: new Date() });
const lastLoginAt = moment().format('YYYY/MM/DD HH:mm:ss');
const updateTenantUser = TenantUser.tenant().query()
.where('id', user.id)
.update({ last_login_at: lastLoginAt });
const updateSystemUser = SystemUser.query()
.where('id', user.id)
.update({ last_login_at: lastLoginAt });
await Promise.all([updateTenantUser, updateSystemUser]);
const token = jwt.sign(
{ email: user.email, _id: user.id },