.
This commit is contained in:
parent
afb5d0883c
commit
093f7244da
@ -97,7 +97,9 @@ passport.use('local-phone', new LocalStrategy(localPhoneOptions, async (phone, f
|
|||||||
|
|
||||||
// JWT
|
// JWT
|
||||||
passport.use('jwt', new CustomStrategy(async (req, done) => {
|
passport.use('jwt', new CustomStrategy(async (req, done) => {
|
||||||
|
|
||||||
const token = ((req && req.headers && req.headers['x-access-token']) ? req.headers['x-access-token'] : null);
|
const token = ((req && req.headers && req.headers['x-access-token']) ? req.headers['x-access-token'] : null);
|
||||||
|
console.log('PASSPORT JWT', token);
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return done(null, false, { message: 'Unauthorized. Token missing.'});
|
return done(null, false, { message: 'Unauthorized. Token missing.'});
|
||||||
@ -107,7 +109,8 @@ passport.use('jwt', new CustomStrategy(async (req, done) => {
|
|||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
//recuperamos el usuario de la petición
|
//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){
|
if (user){
|
||||||
return done(null, user, { message: 'Logged in Successfully' });
|
return done(null, user, { message: 'Logged in Successfully' });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,16 +126,27 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
|
|||||||
|
|
||||||
const defaultService = {
|
const defaultService = {
|
||||||
fetchAssociation: async(params, context) => {
|
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);
|
const associationName = hasAssociation(params);
|
||||||
console.log('associationName => ', associationName);
|
console.log('associationName => ', associationName);
|
||||||
delete params.params.association;
|
delete params.params.association;
|
||||||
|
|
||||||
const associationInfo = foundModelAssociation(model, associationName);
|
const associationInfo = foundModelAssociation(model, associationName);
|
||||||
if (associationInfo) {
|
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 = {
|
const details = {
|
||||||
rows: await master[associationInfo.getFunc](),
|
rows: detailRows,
|
||||||
count: await master[associationInfo.countFunc]()
|
count: detailRows.length
|
||||||
}
|
}
|
||||||
return details;
|
return details;
|
||||||
} else {
|
} else {
|
||||||
@ -155,9 +166,6 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
|
|||||||
// Necesario para el cálculo del count
|
// Necesario para el cálculo del count
|
||||||
// https://github.com/sequelize/sequelize/issues/10557
|
// https://github.com/sequelize/sequelize/issues/10557
|
||||||
findOptions.distinct = true;
|
findOptions.distinct = true;
|
||||||
// findOptions.col = model.primaryKey;
|
|
||||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
|
|
||||||
console.log(findOptions);
|
|
||||||
|
|
||||||
const result = await model.scope(context.scopes).findAndCountAll(findOptions);
|
const result = await model.scope(context.scopes).findAndCountAll(findOptions);
|
||||||
|
|
||||||
|
|||||||
@ -60,6 +60,7 @@ async function loginWithPhone(req, res, next) {
|
|||||||
|
|
||||||
//Comprobamos si el usuario ya existe en nuestro sistema
|
//Comprobamos si el usuario ya existe en nuestro sistema
|
||||||
let _user = await authService.extraMethods.findUser(findOptions);
|
let _user = await authService.extraMethods.findUser(findOptions);
|
||||||
|
_user = _user.toJSON();
|
||||||
|
|
||||||
const tokenData = {
|
const tokenData = {
|
||||||
id: _user.id,
|
id: _user.id,
|
||||||
@ -114,7 +115,6 @@ async function register(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
newUser = await authService.extraMethods.createUser(data);
|
newUser = await authService.extraMethods.createUser(data);
|
||||||
newUser = newUser.toJSON();
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -123,6 +123,7 @@ async function register(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (newUser) {
|
if (newUser) {
|
||||||
|
newUser = newUser.toJSON();
|
||||||
newUser = cleanAdminData(newUser);
|
newUser = cleanAdminData(newUser);
|
||||||
newUser.token = tokens.token;
|
newUser.token = tokens.token;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,6 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
attributes: ['name', 'surname', 'profile_picture'],
|
attributes: ['name', 'surname', 'profile_picture'],
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Comment.addScope('onlyEvents', () => {
|
Comment.addScope('onlyEvents', () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user