Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0575e9d1e6 |
@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn('users', 'country_of_origin', {
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
|
}, { transaction });
|
||||||
|
await queryInterface.addColumn('users', 'visa_type', {
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
|
}, { transaction });
|
||||||
|
await queryInterface.addColumn('users', 'arrival_date', {
|
||||||
|
type: Sequelize.DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
}, { transaction });
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('users', 'country_of_origin', { transaction });
|
||||||
|
await queryInterface.removeColumn('users', 'visa_type', { transaction });
|
||||||
|
await queryInterface.removeColumn('users', 'arrival_date', { transaction });
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
const [roles] = await queryInterface.sequelize.query(
|
||||||
|
"SELECT id FROM roles WHERE name = 'Public' LIMIT 1;",
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
const publicRoleId = roles[0]?.id;
|
||||||
|
|
||||||
|
if (!publicRoleId) {
|
||||||
|
throw new Error("Public role not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const permissionsToGrant = [
|
||||||
|
'READ_POSTS',
|
||||||
|
'READ_SERVICE_CATALOG_ITEMS',
|
||||||
|
'READ_POST_CATEGORIES'
|
||||||
|
];
|
||||||
|
|
||||||
|
const [permissions] = await queryInterface.sequelize.query(
|
||||||
|
`SELECT id FROM permissions WHERE name IN (${permissionsToGrant.map(p => `'${p}'`).join(',')});`,
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
|
||||||
|
const records = permissions.map(p => ({
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
roles_permissionsId: publicRoleId,
|
||||||
|
permissionId: p.id
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (records.length > 0) {
|
||||||
|
await queryInterface.bulkInsert('rolesPermissionsPermissions', records, { transaction });
|
||||||
|
}
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
// Implementation of down migration if needed
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -16,94 +16,68 @@ module.exports = function(sequelize, DataTypes) {
|
|||||||
|
|
||||||
firstName: {
|
firstName: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
lastName: {
|
lastName: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
phoneNumber: {
|
phoneNumber: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
email: {
|
email: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
disabled: {
|
disabled: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
|
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
password: {
|
password: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
emailVerified: {
|
emailVerified: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
|
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
emailVerificationToken: {
|
emailVerificationToken: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
emailVerificationTokenExpiresAt: {
|
emailVerificationTokenExpiresAt: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
passwordResetToken: {
|
passwordResetToken: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
passwordResetTokenExpiresAt: {
|
passwordResetTokenExpiresAt: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
provider: {
|
provider: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
country_of_origin: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
visa_type: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
arrival_date: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
},
|
||||||
|
|
||||||
importHash: {
|
importHash: {
|
||||||
type: DataTypes.STRING(255),
|
type: DataTypes.STRING(255),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
@ -324,4 +298,3 @@ function trimStringFields(users) {
|
|||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -117,7 +117,7 @@ app.use('/api/roles', passport.authenticate('jwt', {session: false}), rolesRoute
|
|||||||
|
|
||||||
app.use('/api/permissions', passport.authenticate('jwt', {session: false}), permissionsRoutes);
|
app.use('/api/permissions', passport.authenticate('jwt', {session: false}), permissionsRoutes);
|
||||||
|
|
||||||
app.use('/api/service_catalog_items', passport.authenticate('jwt', {session: false}), service_catalog_itemsRoutes);
|
app.use('/api/service_catalog_items', service_catalog_itemsRoutes);
|
||||||
|
|
||||||
app.use('/api/service_requests', passport.authenticate('jwt', {session: false}), service_requestsRoutes);
|
app.use('/api/service_requests', passport.authenticate('jwt', {session: false}), service_requestsRoutes);
|
||||||
|
|
||||||
@ -125,9 +125,9 @@ app.use('/api/service_updates', passport.authenticate('jwt', {session: false}),
|
|||||||
|
|
||||||
app.use('/api/service_documents', passport.authenticate('jwt', {session: false}), service_documentsRoutes);
|
app.use('/api/service_documents', passport.authenticate('jwt', {session: false}), service_documentsRoutes);
|
||||||
|
|
||||||
app.use('/api/post_categories', passport.authenticate('jwt', {session: false}), post_categoriesRoutes);
|
app.use('/api/post_categories', post_categoriesRoutes);
|
||||||
|
|
||||||
app.use('/api/posts', passport.authenticate('jwt', {session: false}), postsRoutes);
|
app.use('/api/posts', postsRoutes);
|
||||||
|
|
||||||
app.use('/api/post_comments', passport.authenticate('jwt', {session: false}), post_commentsRoutes);
|
app.use('/api/post_comments', passport.authenticate('jwt', {session: false}), post_commentsRoutes);
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const config = require('../config');
|
|||||||
const helpers = require('../helpers');
|
const helpers = require('../helpers');
|
||||||
|
|
||||||
class Auth {
|
class Auth {
|
||||||
static async signup(email, password, options = {}, host) {
|
static async signup(email, password, extraData = {}, options = {}, host) {
|
||||||
const user = await UsersDBApi.findBy({email});
|
const user = await UsersDBApi.findBy({email});
|
||||||
|
|
||||||
const hashedPassword = await bcrypt.hash(
|
const hashedPassword = await bcrypt.hash(
|
||||||
@ -59,7 +59,7 @@ class Auth {
|
|||||||
firstName: email.split('@')[0],
|
firstName: email.split('@')[0],
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
email: email,
|
email: email,
|
||||||
|
...extraData
|
||||||
},
|
},
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user