This commit is contained in:
David Arranz 2019-08-05 12:55:24 +02:00
parent afb5d0883c
commit 093f7244da
4 changed files with 21 additions and 10 deletions

View File

@ -97,7 +97,9 @@ passport.use('local-phone', new LocalStrategy(localPhoneOptions, async (phone, f
// JWT
passport.use('jwt', new CustomStrategy(async (req, done) => {
const token = ((req && req.headers && req.headers['x-access-token']) ? req.headers['x-access-token'] : null);
console.log('PASSPORT JWT', token);
if (!token) {
return done(null, false, { message: 'Unauthorized. Token missing.'});
@ -107,7 +109,8 @@ passport.use('jwt', new CustomStrategy(async (req, done) => {
if (result) {
//recuperamos el usuario de la petición
let user = await authService.extraMethods.findUser({ phone: result.phone});
console.log(result);
let user = await authService.extraMethods.findUser({ id: result.id });
if (user){
return done(null, user, { message: 'Logged in Successfully' });
}

View File

@ -126,16 +126,27 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
const defaultService = {
fetchAssociation: async(params, context) => {
const _fetchOne = async (params, context) => {
const findOptions = parseParamsToFindOptions(params);
return await model.scope(context.scopes).findOne(findOptions);
};
const associationName = hasAssociation(params);
console.log('associationName => ', associationName);
delete params.params.association;
const associationInfo = foundModelAssociation(model, associationName);
if (associationInfo) {
const master = await defaultService.fetchOne(params, context);
console.log(associationInfo);
const master = await _fetchOne(params, context);
console.log(master);
const detailRows = await master[associationInfo.getFunc]();
const details = {
rows: await master[associationInfo.getFunc](),
count: await master[associationInfo.countFunc]()
rows: detailRows,
count: detailRows.length
}
return details;
} else {
@ -155,9 +166,6 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
// Necesario para el cálculo del count
// https://github.com/sequelize/sequelize/issues/10557
findOptions.distinct = true;
// findOptions.col = model.primaryKey;
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
console.log(findOptions);
const result = await model.scope(context.scopes).findAndCountAll(findOptions);

View File

@ -60,6 +60,7 @@ async function loginWithPhone(req, res, next) {
//Comprobamos si el usuario ya existe en nuestro sistema
let _user = await authService.extraMethods.findUser(findOptions);
_user = _user.toJSON();
const tokenData = {
id: _user.id,
@ -113,8 +114,7 @@ async function register(req, res, next) {
accessibility: req.body.accesssibility
};
newUser = await authService.extraMethods.createUser(data);
newUser = newUser.toJSON();
newUser = await authService.extraMethods.createUser(data);
} catch (error) {
console.error(error);
@ -123,6 +123,7 @@ async function register(req, res, next) {
};
if (newUser) {
newUser = newUser.toJSON();
newUser = cleanAdminData(newUser);
newUser.token = tokens.token;
}

View File

@ -39,7 +39,6 @@ module.exports = function (sequelize, DataTypes) {
attributes: ['name', 'surname', 'profile_picture'],
}]
},
});
Comment.addScope('onlyEvents', () => {