Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,8 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
*/node_modules/
|
*/node_modules/
|
||||||
*/build/
|
*/build/
|
||||||
|
|
||||||
**/node_modules/
|
|
||||||
**/build/
|
|
||||||
.DS_Store
|
|
||||||
.env
|
|
||||||
File diff suppressed because one or more lines are too long
@ -151,10 +151,6 @@ module.exports = class AgenciesDBApi {
|
|||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
output.cart_agencies = await agencies.getCart_agencies({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,333 +0,0 @@
|
|||||||
const db = require('../models');
|
|
||||||
const FileDBApi = require('./file');
|
|
||||||
const crypto = require('crypto');
|
|
||||||
const Utils = require('../utils');
|
|
||||||
|
|
||||||
const Sequelize = db.Sequelize;
|
|
||||||
const Op = Sequelize.Op;
|
|
||||||
|
|
||||||
module.exports = class CartDBApi {
|
|
||||||
static async create(data, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const cart = await db.cart.create(
|
|
||||||
{
|
|
||||||
id: data.id || undefined,
|
|
||||||
|
|
||||||
importHash: data.importHash || null,
|
|
||||||
createdById: currentUser.id,
|
|
||||||
updatedById: currentUser.id,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await cart.setAgencies(data.agencies || null, {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await cart.setUser(data.user || null, {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async bulkImport(data, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
// Prepare data - wrapping individual data transformations in a map() method
|
|
||||||
const cartData = data.map((item, index) => ({
|
|
||||||
id: item.id || undefined,
|
|
||||||
|
|
||||||
importHash: item.importHash || null,
|
|
||||||
createdById: currentUser.id,
|
|
||||||
updatedById: currentUser.id,
|
|
||||||
createdAt: new Date(Date.now() + index * 1000),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Bulk create items
|
|
||||||
const cart = await db.cart.bulkCreate(cartData, { transaction });
|
|
||||||
|
|
||||||
// For each item created, replace relation files
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async update(id, data, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
const globalAccess = currentUser.app_role?.globalAccess;
|
|
||||||
|
|
||||||
const cart = await db.cart.findByPk(id, {}, { transaction });
|
|
||||||
|
|
||||||
const updatePayload = {};
|
|
||||||
|
|
||||||
updatePayload.updatedById = currentUser.id;
|
|
||||||
|
|
||||||
await cart.update(updatePayload, { transaction });
|
|
||||||
|
|
||||||
if (data.agencies !== undefined) {
|
|
||||||
await cart.setAgencies(
|
|
||||||
data.agencies,
|
|
||||||
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.user !== undefined) {
|
|
||||||
await cart.setUser(
|
|
||||||
data.user,
|
|
||||||
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async deleteByIds(ids, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const cart = await db.cart.findAll({
|
|
||||||
where: {
|
|
||||||
id: {
|
|
||||||
[Op.in]: ids,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await db.sequelize.transaction(async (transaction) => {
|
|
||||||
for (const record of cart) {
|
|
||||||
await record.update({ deletedBy: currentUser.id }, { transaction });
|
|
||||||
}
|
|
||||||
for (const record of cart) {
|
|
||||||
await record.destroy({ transaction });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async remove(id, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const cart = await db.cart.findByPk(id, options);
|
|
||||||
|
|
||||||
await cart.update(
|
|
||||||
{
|
|
||||||
deletedBy: currentUser.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
transaction,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await cart.destroy({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findBy(where, options) {
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const cart = await db.cart.findOne({ where }, { transaction });
|
|
||||||
|
|
||||||
if (!cart) {
|
|
||||||
return cart;
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = cart.get({ plain: true });
|
|
||||||
|
|
||||||
output.agencies = await cart.getAgencies({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
output.user = await cart.getUser({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findAll(filter, globalAccess, options) {
|
|
||||||
const limit = filter.limit || 0;
|
|
||||||
let offset = 0;
|
|
||||||
let where = {};
|
|
||||||
const currentPage = +filter.page;
|
|
||||||
|
|
||||||
const user = (options && options.currentUser) || null;
|
|
||||||
const userAgencies = (user && user.agencies?.id) || null;
|
|
||||||
|
|
||||||
if (userAgencies) {
|
|
||||||
if (options?.currentUser?.agenciesId) {
|
|
||||||
where.agenciesId = options.currentUser.agenciesId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = currentPage * limit;
|
|
||||||
|
|
||||||
const orderBy = null;
|
|
||||||
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
let include = [
|
|
||||||
{
|
|
||||||
model: db.agencies,
|
|
||||||
as: 'agencies',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
model: db.users,
|
|
||||||
as: 'user',
|
|
||||||
|
|
||||||
where: filter.user
|
|
||||||
? {
|
|
||||||
[Op.or]: [
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
[Op.in]: filter.user
|
|
||||||
.split('|')
|
|
||||||
.map((term) => Utils.uuid(term)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
firstName: {
|
|
||||||
[Op.or]: filter.user
|
|
||||||
.split('|')
|
|
||||||
.map((term) => ({ [Op.iLike]: `%${term}%` })),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
: {},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (filter) {
|
|
||||||
if (filter.id) {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
['id']: Utils.uuid(filter.id),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.active !== undefined) {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
active: filter.active === true || filter.active === 'true',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.agencies) {
|
|
||||||
const listItems = filter.agencies.split('|').map((item) => {
|
|
||||||
return Utils.uuid(item);
|
|
||||||
});
|
|
||||||
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
agenciesId: { [Op.or]: listItems },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.createdAtRange) {
|
|
||||||
const [start, end] = filter.createdAtRange;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
['createdAt']: {
|
|
||||||
...where.createdAt,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
['createdAt']: {
|
|
||||||
...where.createdAt,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalAccess) {
|
|
||||||
delete where.agenciesId;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryOptions = {
|
|
||||||
where,
|
|
||||||
include,
|
|
||||||
distinct: true,
|
|
||||||
order:
|
|
||||||
filter.field && filter.sort
|
|
||||||
? [[filter.field, filter.sort]]
|
|
||||||
: [['createdAt', 'desc']],
|
|
||||||
transaction: options?.transaction,
|
|
||||||
logging: console.log,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!options?.countOnly) {
|
|
||||||
queryOptions.limit = limit ? Number(limit) : undefined;
|
|
||||||
queryOptions.offset = offset ? Number(offset) : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { rows, count } = await db.cart.findAndCountAll(queryOptions);
|
|
||||||
|
|
||||||
return {
|
|
||||||
rows: options?.countOnly ? [] : rows,
|
|
||||||
count: count,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error executing query:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findAllAutocomplete(
|
|
||||||
query,
|
|
||||||
limit,
|
|
||||||
offset,
|
|
||||||
globalAccess,
|
|
||||||
organizationId,
|
|
||||||
) {
|
|
||||||
let where = {};
|
|
||||||
|
|
||||||
if (!globalAccess && organizationId) {
|
|
||||||
where.organizationId = organizationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query) {
|
|
||||||
where = {
|
|
||||||
[Op.or]: [
|
|
||||||
{ ['id']: Utils.uuid(query) },
|
|
||||||
Utils.ilike('cart', 'id', query),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const records = await db.cart.findAll({
|
|
||||||
attributes: ['id', 'id'],
|
|
||||||
where,
|
|
||||||
limit: limit ? Number(limit) : undefined,
|
|
||||||
offset: offset ? Number(offset) : undefined,
|
|
||||||
orderBy: [['id', 'ASC']],
|
|
||||||
});
|
|
||||||
|
|
||||||
return records.map((record) => ({
|
|
||||||
id: record.id,
|
|
||||||
label: record.id,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -20,7 +20,6 @@ module.exports = class ToursDBApi {
|
|||||||
price: data.price || null,
|
price: data.price || null,
|
||||||
start_date: data.start_date || null,
|
start_date: data.start_date || null,
|
||||||
end_date: data.end_date || null,
|
end_date: data.end_date || null,
|
||||||
image_url: data.image_url || null,
|
|
||||||
importHash: data.importHash || null,
|
importHash: data.importHash || null,
|
||||||
createdById: currentUser.id,
|
createdById: currentUser.id,
|
||||||
updatedById: currentUser.id,
|
updatedById: currentUser.id,
|
||||||
@ -52,7 +51,6 @@ module.exports = class ToursDBApi {
|
|||||||
price: item.price || null,
|
price: item.price || null,
|
||||||
start_date: item.start_date || null,
|
start_date: item.start_date || null,
|
||||||
end_date: item.end_date || null,
|
end_date: item.end_date || null,
|
||||||
image_url: item.image_url || null,
|
|
||||||
importHash: item.importHash || null,
|
importHash: item.importHash || null,
|
||||||
createdById: currentUser.id,
|
createdById: currentUser.id,
|
||||||
updatedById: currentUser.id,
|
updatedById: currentUser.id,
|
||||||
@ -88,8 +86,6 @@ module.exports = class ToursDBApi {
|
|||||||
|
|
||||||
if (data.end_date !== undefined) updatePayload.end_date = data.end_date;
|
if (data.end_date !== undefined) updatePayload.end_date = data.end_date;
|
||||||
|
|
||||||
if (data.image_url !== undefined) updatePayload.image_url = data.image_url;
|
|
||||||
|
|
||||||
updatePayload.updatedById = currentUser.id;
|
updatePayload.updatedById = currentUser.id;
|
||||||
|
|
||||||
await tours.update(updatePayload, { transaction });
|
await tours.update(updatePayload, { transaction });
|
||||||
@ -175,10 +171,6 @@ module.exports = class ToursDBApi {
|
|||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
output.cartitem_tour = await tours.getCartitem_tour({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
output.agency = await tours.getAgency({
|
output.agency = await tours.getAgency({
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
@ -245,13 +237,6 @@ module.exports = class ToursDBApi {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.image_url) {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
[Op.and]: Utils.ilike('tours', 'image_url', filter.image_url),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.calendarStart && filter.calendarEnd) {
|
if (filter.calendarStart && filter.calendarEnd) {
|
||||||
where = {
|
where = {
|
||||||
...where,
|
...where,
|
||||||
|
|||||||
@ -283,10 +283,6 @@ module.exports = class UsersDBApi {
|
|||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
output.cart_user = await users.getCart_user({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
output.avatar = await users.getAvatar({
|
output.avatar = await users.getAvatar({
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,88 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.createTable(
|
|
||||||
'cart',
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
defaultValue: Sequelize.DataTypes.UUIDV4,
|
|
||||||
primaryKey: true,
|
|
||||||
},
|
|
||||||
createdById: {
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
references: {
|
|
||||||
key: 'id',
|
|
||||||
model: 'users',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
updatedById: {
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
references: {
|
|
||||||
key: 'id',
|
|
||||||
model: 'users',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
createdAt: { type: Sequelize.DataTypes.DATE },
|
|
||||||
updatedAt: { type: Sequelize.DataTypes.DATE },
|
|
||||||
deletedAt: { type: Sequelize.DataTypes.DATE },
|
|
||||||
importHash: {
|
|
||||||
type: Sequelize.DataTypes.STRING(255),
|
|
||||||
allowNull: true,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'cart',
|
|
||||||
'agenciesId',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
|
|
||||||
references: {
|
|
||||||
model: 'agencies',
|
|
||||||
key: 'id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('cart', 'agenciesId', { transaction });
|
|
||||||
|
|
||||||
await queryInterface.dropTable('cart', { transaction });
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'cart',
|
|
||||||
'userId',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
|
|
||||||
references: {
|
|
||||||
model: 'users',
|
|
||||||
key: 'id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('cart', 'userId', { transaction });
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'tours',
|
|
||||||
'image_url',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.TEXT,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('tours', 'image_url', { transaction });
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -82,14 +82,6 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
constraints: false,
|
constraints: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
db.agencies.hasMany(db.cart, {
|
|
||||||
as: 'cart_agencies',
|
|
||||||
foreignKey: {
|
|
||||||
name: 'agenciesId',
|
|
||||||
},
|
|
||||||
constraints: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
//end loop
|
//end loop
|
||||||
|
|
||||||
db.agencies.belongsTo(db.users, {
|
db.agencies.belongsTo(db.users, {
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
const config = require('../../config');
|
|
||||||
const providers = config.providers;
|
|
||||||
const crypto = require('crypto');
|
|
||||||
const bcrypt = require('bcrypt');
|
|
||||||
const moment = require('moment');
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
|
||||||
const cart = sequelize.define(
|
|
||||||
'cart',
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
importHash: {
|
|
||||||
type: DataTypes.STRING(255),
|
|
||||||
allowNull: true,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timestamps: true,
|
|
||||||
paranoid: true,
|
|
||||||
freezeTableName: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
cart.associate = (db) => {
|
|
||||||
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
||||||
|
|
||||||
//end loop
|
|
||||||
|
|
||||||
db.cart.belongsTo(db.agencies, {
|
|
||||||
as: 'agencies',
|
|
||||||
foreignKey: {
|
|
||||||
name: 'agenciesId',
|
|
||||||
},
|
|
||||||
constraints: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
db.cart.belongsTo(db.users, {
|
|
||||||
as: 'user',
|
|
||||||
foreignKey: {
|
|
||||||
name: 'userId',
|
|
||||||
},
|
|
||||||
constraints: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
db.cart.belongsTo(db.users, {
|
|
||||||
as: 'createdBy',
|
|
||||||
});
|
|
||||||
|
|
||||||
db.cart.belongsTo(db.users, {
|
|
||||||
as: 'updatedBy',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
};
|
|
||||||
@ -34,10 +34,6 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
},
|
},
|
||||||
|
|
||||||
image_url: {
|
|
||||||
type: DataTypes.TEXT,
|
|
||||||
},
|
|
||||||
|
|
||||||
importHash: {
|
importHash: {
|
||||||
type: DataTypes.STRING(255),
|
type: DataTypes.STRING(255),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
@ -62,14 +58,6 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
constraints: false,
|
constraints: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
db.tours.hasMany(db.cartitem, {
|
|
||||||
as: 'cartitem_tour',
|
|
||||||
foreignKey: {
|
|
||||||
name: 'tourId',
|
|
||||||
},
|
|
||||||
constraints: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
//end loop
|
//end loop
|
||||||
|
|
||||||
db.tours.belongsTo(db.agencies, {
|
db.tours.belongsTo(db.agencies, {
|
||||||
|
|||||||
@ -110,14 +110,6 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
constraints: false,
|
constraints: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
db.users.hasMany(db.cart, {
|
|
||||||
as: 'cart_user',
|
|
||||||
foreignKey: {
|
|
||||||
name: 'userId',
|
|
||||||
},
|
|
||||||
constraints: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
//end loop
|
//end loop
|
||||||
|
|
||||||
db.users.belongsTo(db.roles, {
|
db.users.belongsTo(db.roles, {
|
||||||
|
|||||||
@ -108,7 +108,6 @@ module.exports = {
|
|||||||
'roles',
|
'roles',
|
||||||
'permissions',
|
'permissions',
|
||||||
'agencies',
|
'agencies',
|
||||||
'cart',
|
|
||||||
,
|
,
|
||||||
];
|
];
|
||||||
await queryInterface.bulkInsert(
|
await queryInterface.bulkInsert(
|
||||||
@ -578,31 +577,6 @@ primary key ("roles_permissionsId", "permissionId")
|
|||||||
permissionId: getId('DELETE_TOURS'),
|
permissionId: getId('DELETE_TOURS'),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('CREATE_CART'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('READ_CART'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('UPDATE_CART'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('DELETE_CART'),
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
createdAt,
|
createdAt,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
@ -778,31 +752,6 @@ primary key ("roles_permissionsId", "permissionId")
|
|||||||
permissionId: getId('DELETE_AGENCIES'),
|
permissionId: getId('DELETE_AGENCIES'),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('SuperAdmin'),
|
|
||||||
permissionId: getId('CREATE_CART'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('SuperAdmin'),
|
|
||||||
permissionId: getId('READ_CART'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('SuperAdmin'),
|
|
||||||
permissionId: getId('UPDATE_CART'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('SuperAdmin'),
|
|
||||||
permissionId: getId('DELETE_CART'),
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
createdAt,
|
createdAt,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
|
|||||||
@ -9,10 +9,6 @@ const Tours = db.tours;
|
|||||||
|
|
||||||
const Agencies = db.agencies;
|
const Agencies = db.agencies;
|
||||||
|
|
||||||
const Cart = db.cart;
|
|
||||||
|
|
||||||
const Cartitem = db.cartitem;
|
|
||||||
|
|
||||||
const AgentsData = [
|
const AgentsData = [
|
||||||
{
|
{
|
||||||
name: 'Alice Green',
|
name: 'Alice Green',
|
||||||
@ -43,6 +39,26 @@ const AgentsData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'Diana Blue',
|
||||||
|
|
||||||
|
commission_rate: 0.08,
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'Eve Red',
|
||||||
|
|
||||||
|
commission_rate: 0.11,
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const BookingsData = [
|
const BookingsData = [
|
||||||
@ -65,7 +81,7 @@ const BookingsData = [
|
|||||||
|
|
||||||
booking_date: new Date('2023-12-05T11:00:00Z'),
|
booking_date: new Date('2023-12-05T11:00:00Z'),
|
||||||
|
|
||||||
status: 'pending',
|
status: 'cancelled',
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
},
|
},
|
||||||
@ -81,6 +97,30 @@ const BookingsData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
booking_date: new Date('2023-12-15T13:00:00Z'),
|
||||||
|
|
||||||
|
status: 'cancelled',
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
booking_date: new Date('2023-12-20T14:00:00Z'),
|
||||||
|
|
||||||
|
status: 'confirmed',
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ToursData = [
|
const ToursData = [
|
||||||
@ -98,8 +138,6 @@ const ToursData = [
|
|||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
image_url: 'Alfred Wegener',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -116,8 +154,6 @@ const ToursData = [
|
|||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
image_url: 'Konrad Lorenz',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -134,8 +170,38 @@ const ToursData = [
|
|||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
|
|
||||||
image_url: 'Alfred Kinsey',
|
{
|
||||||
|
title: 'Red Sea Diving Experience',
|
||||||
|
|
||||||
|
description: 'Dive into the vibrant underwater world of the Red Sea.',
|
||||||
|
|
||||||
|
price: 1000,
|
||||||
|
|
||||||
|
start_date: new Date('2024-04-01T09:00:00Z'),
|
||||||
|
|
||||||
|
end_date: new Date('2024-04-07T18:00:00Z'),
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: 'Alexandria Cultural Journey',
|
||||||
|
|
||||||
|
description: 'Immerse yourself in the rich history of Alexandria.',
|
||||||
|
|
||||||
|
price: 900,
|
||||||
|
|
||||||
|
start_date: new Date('2024-05-15T09:00:00Z'),
|
||||||
|
|
||||||
|
end_date: new Date('2024-05-20T18:00:00Z'),
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -151,63 +217,13 @@ const AgenciesData = [
|
|||||||
{
|
{
|
||||||
name: 'Adventure Seekers',
|
name: 'Adventure Seekers',
|
||||||
},
|
},
|
||||||
];
|
|
||||||
|
|
||||||
const CartData = [
|
|
||||||
{
|
{
|
||||||
// type code here for "relation_one" field
|
name: 'Cultural Journeys',
|
||||||
// type code here for "relation_one" field
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
// type code here for "relation_one" field
|
name: 'Luxury Escapes',
|
||||||
// type code here for "relation_one" field
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const CartitemData = [
|
|
||||||
{
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
quantity: 7,
|
|
||||||
|
|
||||||
unitprice: 13.85,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
quantity: 7,
|
|
||||||
|
|
||||||
unitprice: 88.36,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
quantity: 4,
|
|
||||||
|
|
||||||
unitprice: 36.29,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -246,40 +262,27 @@ async function associateUserWithAgency() {
|
|||||||
if (User2?.setAgency) {
|
if (User2?.setAgency) {
|
||||||
await User2.setAgency(relatedAgency2);
|
await User2.setAgency(relatedAgency2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function associateAgentWithAgency() {
|
const relatedAgency3 = await Agencies.findOne({
|
||||||
const relatedAgency0 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Agent0 = await Agents.findOne({
|
const User3 = await Users.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 0,
|
offset: 3,
|
||||||
});
|
});
|
||||||
if (Agent0?.setAgency) {
|
if (User3?.setAgency) {
|
||||||
await Agent0.setAgency(relatedAgency0);
|
await User3.setAgency(relatedAgency3);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedAgency1 = await Agencies.findOne({
|
const relatedAgency4 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Agent1 = await Agents.findOne({
|
const User4 = await Users.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 1,
|
offset: 4,
|
||||||
});
|
});
|
||||||
if (Agent1?.setAgency) {
|
if (User4?.setAgency) {
|
||||||
await Agent1.setAgency(relatedAgency1);
|
await User4.setAgency(relatedAgency4);
|
||||||
}
|
|
||||||
|
|
||||||
const relatedAgency2 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
||||||
});
|
|
||||||
const Agent2 = await Agents.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Agent2?.setAgency) {
|
|
||||||
await Agent2.setAgency(relatedAgency2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,6 +319,85 @@ async function associateAgentWithAgency() {
|
|||||||
if (Agent2?.setAgency) {
|
if (Agent2?.setAgency) {
|
||||||
await Agent2.setAgency(relatedAgency2);
|
await Agent2.setAgency(relatedAgency2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedAgency3 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent3 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Agent3?.setAgency) {
|
||||||
|
await Agent3.setAgency(relatedAgency3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedAgency4 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent4 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Agent4?.setAgency) {
|
||||||
|
await Agent4.setAgency(relatedAgency4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function associateAgentWithAgency() {
|
||||||
|
const relatedAgency0 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent0 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 0,
|
||||||
|
});
|
||||||
|
if (Agent0?.setAgency) {
|
||||||
|
await Agent0.setAgency(relatedAgency0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedAgency1 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent1 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 1,
|
||||||
|
});
|
||||||
|
if (Agent1?.setAgency) {
|
||||||
|
await Agent1.setAgency(relatedAgency1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedAgency2 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent2 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 2,
|
||||||
|
});
|
||||||
|
if (Agent2?.setAgency) {
|
||||||
|
await Agent2.setAgency(relatedAgency2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedAgency3 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent3 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Agent3?.setAgency) {
|
||||||
|
await Agent3.setAgency(relatedAgency3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedAgency4 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Agent4 = await Agents.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Agent4?.setAgency) {
|
||||||
|
await Agent4.setAgency(relatedAgency4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateBookingWithTour() {
|
async function associateBookingWithTour() {
|
||||||
@ -351,6 +433,28 @@ async function associateBookingWithTour() {
|
|||||||
if (Booking2?.setTour) {
|
if (Booking2?.setTour) {
|
||||||
await Booking2.setTour(relatedTour2);
|
await Booking2.setTour(relatedTour2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedTour3 = await Tours.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Tours.count())),
|
||||||
|
});
|
||||||
|
const Booking3 = await Bookings.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Booking3?.setTour) {
|
||||||
|
await Booking3.setTour(relatedTour3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedTour4 = await Tours.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Tours.count())),
|
||||||
|
});
|
||||||
|
const Booking4 = await Bookings.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Booking4?.setTour) {
|
||||||
|
await Booking4.setTour(relatedTour4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateBookingWithCustomer() {
|
async function associateBookingWithCustomer() {
|
||||||
@ -386,6 +490,28 @@ async function associateBookingWithCustomer() {
|
|||||||
if (Booking2?.setCustomer) {
|
if (Booking2?.setCustomer) {
|
||||||
await Booking2.setCustomer(relatedCustomer2);
|
await Booking2.setCustomer(relatedCustomer2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedCustomer3 = await Users.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Users.count())),
|
||||||
|
});
|
||||||
|
const Booking3 = await Bookings.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Booking3?.setCustomer) {
|
||||||
|
await Booking3.setCustomer(relatedCustomer3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedCustomer4 = await Users.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Users.count())),
|
||||||
|
});
|
||||||
|
const Booking4 = await Bookings.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Booking4?.setCustomer) {
|
||||||
|
await Booking4.setCustomer(relatedCustomer4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateBookingWithAgency() {
|
async function associateBookingWithAgency() {
|
||||||
@ -421,40 +547,27 @@ async function associateBookingWithAgency() {
|
|||||||
if (Booking2?.setAgency) {
|
if (Booking2?.setAgency) {
|
||||||
await Booking2.setAgency(relatedAgency2);
|
await Booking2.setAgency(relatedAgency2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function associateTourWithAgency() {
|
const relatedAgency3 = await Agencies.findOne({
|
||||||
const relatedAgency0 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Tour0 = await Tours.findOne({
|
const Booking3 = await Bookings.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 0,
|
offset: 3,
|
||||||
});
|
});
|
||||||
if (Tour0?.setAgency) {
|
if (Booking3?.setAgency) {
|
||||||
await Tour0.setAgency(relatedAgency0);
|
await Booking3.setAgency(relatedAgency3);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedAgency1 = await Agencies.findOne({
|
const relatedAgency4 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Tour1 = await Tours.findOne({
|
const Booking4 = await Bookings.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 1,
|
offset: 4,
|
||||||
});
|
});
|
||||||
if (Tour1?.setAgency) {
|
if (Booking4?.setAgency) {
|
||||||
await Tour1.setAgency(relatedAgency1);
|
await Booking4.setAgency(relatedAgency4);
|
||||||
}
|
|
||||||
|
|
||||||
const relatedAgency2 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
||||||
});
|
|
||||||
const Tour2 = await Tours.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Tour2?.setAgency) {
|
|
||||||
await Tour2.setAgency(relatedAgency2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,215 +604,84 @@ async function associateTourWithAgency() {
|
|||||||
if (Tour2?.setAgency) {
|
if (Tour2?.setAgency) {
|
||||||
await Tour2.setAgency(relatedAgency2);
|
await Tour2.setAgency(relatedAgency2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedAgency3 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Tour3 = await Tours.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Tour3?.setAgency) {
|
||||||
|
await Tour3.setAgency(relatedAgency3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedAgency4 = await Agencies.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
|
});
|
||||||
|
const Tour4 = await Tours.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Tour4?.setAgency) {
|
||||||
|
await Tour4.setAgency(relatedAgency4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateCartWithAgency() {
|
async function associateTourWithAgency() {
|
||||||
const relatedAgency0 = await Agencies.findOne({
|
const relatedAgency0 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Cart0 = await Cart.findOne({
|
const Tour0 = await Tours.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 0,
|
offset: 0,
|
||||||
});
|
});
|
||||||
if (Cart0?.setAgency) {
|
if (Tour0?.setAgency) {
|
||||||
await Cart0.setAgency(relatedAgency0);
|
await Tour0.setAgency(relatedAgency0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedAgency1 = await Agencies.findOne({
|
const relatedAgency1 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Cart1 = await Cart.findOne({
|
const Tour1 = await Tours.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 1,
|
offset: 1,
|
||||||
});
|
});
|
||||||
if (Cart1?.setAgency) {
|
if (Tour1?.setAgency) {
|
||||||
await Cart1.setAgency(relatedAgency1);
|
await Tour1.setAgency(relatedAgency1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedAgency2 = await Agencies.findOne({
|
const relatedAgency2 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Cart2 = await Cart.findOne({
|
const Tour2 = await Tours.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 2,
|
offset: 2,
|
||||||
});
|
});
|
||||||
if (Cart2?.setAgency) {
|
if (Tour2?.setAgency) {
|
||||||
await Cart2.setAgency(relatedAgency2);
|
await Tour2.setAgency(relatedAgency2);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function associateCartWithUser() {
|
|
||||||
const relatedUser0 = await Users.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Users.count())),
|
|
||||||
});
|
|
||||||
const Cart0 = await Cart.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 0,
|
|
||||||
});
|
|
||||||
if (Cart0?.setUser) {
|
|
||||||
await Cart0.setUser(relatedUser0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedUser1 = await Users.findOne({
|
const relatedAgency3 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Users.count())),
|
|
||||||
});
|
|
||||||
const Cart1 = await Cart.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 1,
|
|
||||||
});
|
|
||||||
if (Cart1?.setUser) {
|
|
||||||
await Cart1.setUser(relatedUser1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedUser2 = await Users.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Users.count())),
|
|
||||||
});
|
|
||||||
const Cart2 = await Cart.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Cart2?.setUser) {
|
|
||||||
await Cart2.setUser(relatedUser2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function associateCartWithAgency() {
|
|
||||||
const relatedAgency0 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Cart0 = await Cart.findOne({
|
const Tour3 = await Tours.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 0,
|
offset: 3,
|
||||||
});
|
});
|
||||||
if (Cart0?.setAgency) {
|
if (Tour3?.setAgency) {
|
||||||
await Cart0.setAgency(relatedAgency0);
|
await Tour3.setAgency(relatedAgency3);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedAgency1 = await Agencies.findOne({
|
const relatedAgency4 = await Agencies.findOne({
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
||||||
});
|
});
|
||||||
const Cart1 = await Cart.findOne({
|
const Tour4 = await Tours.findOne({
|
||||||
order: [['id', 'ASC']],
|
order: [['id', 'ASC']],
|
||||||
offset: 1,
|
offset: 4,
|
||||||
});
|
});
|
||||||
if (Cart1?.setAgency) {
|
if (Tour4?.setAgency) {
|
||||||
await Cart1.setAgency(relatedAgency1);
|
await Tour4.setAgency(relatedAgency4);
|
||||||
}
|
|
||||||
|
|
||||||
const relatedAgency2 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
||||||
});
|
|
||||||
const Cart2 = await Cart.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Cart2?.setAgency) {
|
|
||||||
await Cart2.setAgency(relatedAgency2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function associateCartitemWithAgency() {
|
|
||||||
const relatedAgency0 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
||||||
});
|
|
||||||
const Cartitem0 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 0,
|
|
||||||
});
|
|
||||||
if (Cartitem0?.setAgency) {
|
|
||||||
await Cartitem0.setAgency(relatedAgency0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedAgency1 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
||||||
});
|
|
||||||
const Cartitem1 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 1,
|
|
||||||
});
|
|
||||||
if (Cartitem1?.setAgency) {
|
|
||||||
await Cartitem1.setAgency(relatedAgency1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedAgency2 = await Agencies.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
||||||
});
|
|
||||||
const Cartitem2 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Cartitem2?.setAgency) {
|
|
||||||
await Cartitem2.setAgency(relatedAgency2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function associateCartitemWithCart() {
|
|
||||||
const relatedCart0 = await Cart.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Cart.count())),
|
|
||||||
});
|
|
||||||
const Cartitem0 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 0,
|
|
||||||
});
|
|
||||||
if (Cartitem0?.setCart) {
|
|
||||||
await Cartitem0.setCart(relatedCart0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedCart1 = await Cart.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Cart.count())),
|
|
||||||
});
|
|
||||||
const Cartitem1 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 1,
|
|
||||||
});
|
|
||||||
if (Cartitem1?.setCart) {
|
|
||||||
await Cartitem1.setCart(relatedCart1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedCart2 = await Cart.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Cart.count())),
|
|
||||||
});
|
|
||||||
const Cartitem2 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Cartitem2?.setCart) {
|
|
||||||
await Cartitem2.setCart(relatedCart2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function associateCartitemWithTour() {
|
|
||||||
const relatedTour0 = await Tours.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Tours.count())),
|
|
||||||
});
|
|
||||||
const Cartitem0 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 0,
|
|
||||||
});
|
|
||||||
if (Cartitem0?.setTour) {
|
|
||||||
await Cartitem0.setTour(relatedTour0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedTour1 = await Tours.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Tours.count())),
|
|
||||||
});
|
|
||||||
const Cartitem1 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 1,
|
|
||||||
});
|
|
||||||
if (Cartitem1?.setTour) {
|
|
||||||
await Cartitem1.setTour(relatedTour1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relatedTour2 = await Tours.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Tours.count())),
|
|
||||||
});
|
|
||||||
const Cartitem2 = await Cartitem.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 2,
|
|
||||||
});
|
|
||||||
if (Cartitem2?.setTour) {
|
|
||||||
await Cartitem2.setTour(relatedTour2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,10 +695,6 @@ module.exports = {
|
|||||||
|
|
||||||
await Agencies.bulkCreate(AgenciesData);
|
await Agencies.bulkCreate(AgenciesData);
|
||||||
|
|
||||||
await Cart.bulkCreate(CartData);
|
|
||||||
|
|
||||||
await Cartitem.bulkCreate(CartitemData);
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
|
|
||||||
@ -735,18 +713,6 @@ module.exports = {
|
|||||||
await associateTourWithAgency(),
|
await associateTourWithAgency(),
|
||||||
|
|
||||||
await associateTourWithAgency(),
|
await associateTourWithAgency(),
|
||||||
|
|
||||||
await associateCartWithAgency(),
|
|
||||||
|
|
||||||
await associateCartWithUser(),
|
|
||||||
|
|
||||||
await associateCartWithAgency(),
|
|
||||||
|
|
||||||
await associateCartitemWithAgency(),
|
|
||||||
|
|
||||||
await associateCartitemWithCart(),
|
|
||||||
|
|
||||||
await associateCartitemWithTour(),
|
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -758,9 +724,5 @@ module.exports = {
|
|||||||
await queryInterface.bulkDelete('tours', null, {});
|
await queryInterface.bulkDelete('tours', null, {});
|
||||||
|
|
||||||
await queryInterface.bulkDelete('agencies', null, {});
|
await queryInterface.bulkDelete('agencies', null, {});
|
||||||
|
|
||||||
await queryInterface.bulkDelete('cart', null, {});
|
|
||||||
|
|
||||||
await queryInterface.bulkDelete('cartitem', null, {});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,75 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
const { v4: uuidv4 } = require('uuid');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: async (queryInterface, Sequelize) => {
|
|
||||||
await queryInterface.bulkInsert('tours', [
|
|
||||||
{
|
|
||||||
id: uuidv4(),
|
|
||||||
title: 'Discover the Mysteries of Thailand',
|
|
||||||
description: '2 nights in Krabi; 3 nights in Phuket; half-day tour of the Emerald Temple & waterfall; 7-Islands long-tail boat cruise with sunset dinner; half-day Phuket city tour with Big Buddha; Phi Phi Islands Maya Bay & Khai speedboat tour with lunch; all transfers via private boat.',
|
|
||||||
price: 1881,
|
|
||||||
start_date: null,
|
|
||||||
end_date: null,
|
|
||||||
image_url: 'https://www.arwatravelksa.com/images/pac2.jpeg',
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: uuidv4(),
|
|
||||||
title: 'Family Adventures in Thailand',
|
|
||||||
description: 'Discover hidden gems, pristine beaches and vibrant cities while experiencing rich culture and hospitality in the Land of Smiles—designed for 2 adults + 1 child.',
|
|
||||||
price: 2600,
|
|
||||||
start_date: null,
|
|
||||||
end_date: null,
|
|
||||||
image_url: 'https://www.arwatravelksa.com/images/486033692_960427122968372_1468632099997282977_n.jpg',
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: uuidv4(),
|
|
||||||
title: 'Turkey Highlights: Trabzon & Istanbul',
|
|
||||||
description: 'Cruise dinner in Istanbul; Princess Island tour; full-day Uzungöl & tea-factory visit; explore the heart of Trabzon.',
|
|
||||||
price: 2850,
|
|
||||||
start_date: null,
|
|
||||||
end_date: null,
|
|
||||||
image_url: 'https://www.arwatravelksa.com/images/pac5.jpeg',
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: uuidv4(),
|
|
||||||
title: 'Turkey – Trabzon & Istanbul (English Version)',
|
|
||||||
description: 'Cruise dinner in Istanbul; Princess Island; full-day Uzungöl tour with tea factory; Heart of Trabzon.',
|
|
||||||
price: null,
|
|
||||||
start_date: null,
|
|
||||||
end_date: null,
|
|
||||||
image_url: 'https://www.arwatravelksa.com/images/pac3.jpeg',
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: uuidv4(),
|
|
||||||
title: 'Azerbaijan Explorer',
|
|
||||||
description: 'Join us for an exciting trip to Qafqaz and Gabala; includes 4-star hotel, daily breakfast, one guided tour and all transport.',
|
|
||||||
price: null,
|
|
||||||
start_date: null,
|
|
||||||
end_date: null,
|
|
||||||
image_url: 'https://www.arwatravelksa.com/images/pac4.jpeg',
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
}
|
|
||||||
], {});
|
|
||||||
},
|
|
||||||
down: async (queryInterface, Sequelize) => {
|
|
||||||
await queryInterface.bulkDelete('tours', {
|
|
||||||
title: [
|
|
||||||
'Discover the Mysteries of Thailand',
|
|
||||||
'Family Adventures in Thailand',
|
|
||||||
'Turkey Highlights: Trabzon & Istanbul',
|
|
||||||
'Turkey – Trabzon & Istanbul (English Version)',
|
|
||||||
'Azerbaijan Explorer'
|
|
||||||
]
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
const { v4: uuid } = require('uuid');
|
|
||||||
const db = require('../models');
|
|
||||||
const Sequelize = require('sequelize');
|
|
||||||
const config = require('../../config');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param{import("sequelize").QueryInterface} queryInterface
|
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface) {
|
|
||||||
const createdAt = new Date();
|
|
||||||
const updatedAt = new Date();
|
|
||||||
|
|
||||||
/** @type {Map<string, string>} */
|
|
||||||
const idMap = new Map();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} key
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
function getId(key) {
|
|
||||||
if (idMap.has(key)) {
|
|
||||||
return idMap.get(key);
|
|
||||||
}
|
|
||||||
const id = uuid();
|
|
||||||
idMap.set(key, id);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} name
|
|
||||||
*/
|
|
||||||
function createPermissions(name) {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: getId(`CREATE_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `CREATE_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: getId(`READ_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `READ_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: getId(`UPDATE_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `UPDATE_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: getId(`DELETE_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `DELETE_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
const entities = ['cart'];
|
|
||||||
|
|
||||||
const createdPermissions = entities.flatMap(createPermissions);
|
|
||||||
|
|
||||||
// Add permissions to database
|
|
||||||
await queryInterface.bulkInsert('permissions', createdPermissions);
|
|
||||||
// Get permissions ids
|
|
||||||
const permissionsIds = createdPermissions.map((p) => p.id);
|
|
||||||
// Get admin role
|
|
||||||
const adminRole = await db.roles.findOne({
|
|
||||||
where: { name: config.roles.super_admin },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (adminRole) {
|
|
||||||
// Add permissions to admin role if it exists
|
|
||||||
await adminRole.addPermissions(permissionsIds);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
down: async (queryInterface, Sequelize) => {
|
|
||||||
await queryInterface.bulkDelete(
|
|
||||||
'permissions',
|
|
||||||
entities.flatMap(createPermissions),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -35,10 +35,6 @@ const permissionsRoutes = require('./routes/permissions');
|
|||||||
|
|
||||||
const agenciesRoutes = require('./routes/agencies');
|
const agenciesRoutes = require('./routes/agencies');
|
||||||
|
|
||||||
const cartRoutes = require('./routes/cart');
|
|
||||||
const amadeusRoutes = require('./routes/amadeus');
|
|
||||||
|
|
||||||
|
|
||||||
const getBaseUrl = (url) => {
|
const getBaseUrl = (url) => {
|
||||||
if (!url) return '';
|
if (!url) return '';
|
||||||
return url.endsWith('/api') ? url.slice(0, -4) : url;
|
return url.endsWith('/api') ? url.slice(0, -4) : url;
|
||||||
@ -146,21 +142,6 @@ app.use(
|
|||||||
agenciesRoutes,
|
agenciesRoutes,
|
||||||
);
|
);
|
||||||
|
|
||||||
app.use(
|
|
||||||
'/api/cart',
|
|
||||||
passport.authenticate('jwt', { session: false }),
|
|
||||||
cartRoutes,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Amadeus flight search routes
|
|
||||||
app.use(
|
|
||||||
'/api/amadeus',
|
|
||||||
passport.authenticate('jwt', { session: false }),
|
|
||||||
amadeusRoutes
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/api/openai',
|
'/api/openai',
|
||||||
passport.authenticate('jwt', { session: false }),
|
passport.authenticate('jwt', { session: false }),
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const wrapAsync = require('../helpers').wrapAsync;
|
|
||||||
const passport = require('passport');
|
|
||||||
const AmadeusService = require('../services/amadeusService');
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @route GET /api/amadeus/flights
|
|
||||||
* @desc Search flights via Amadeus
|
|
||||||
* Query params: originLocationCode, destinationLocationCode, departureDate, adults, currency, etc.
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/flights',
|
|
||||||
passport.authenticate('jwt', { session: false }),
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const params = {
|
|
||||||
originLocationCode: req.query.originLocationCode,
|
|
||||||
destinationLocationCode: req.query.destinationLocationCode,
|
|
||||||
departureDate: req.query.departureDate,
|
|
||||||
adults: req.query.adults || 1,
|
|
||||||
max: req.query.max || 10,
|
|
||||||
currency: req.query.currency || 'SAR'
|
|
||||||
};
|
|
||||||
const result = await AmadeusService.searchFlights(params);
|
|
||||||
res.json(result);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@ -1,488 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
|
|
||||||
const CartService = require('../services/cart');
|
|
||||||
const CartDBApi = require('../db/api/cart');
|
|
||||||
const wrapAsync = require('../helpers').wrapAsync;
|
|
||||||
|
|
||||||
const tapService = require('../services/tapService');
|
|
||||||
const { v4: uuidv4 } = require('uuid');
|
|
||||||
const db = require('../db/models');
|
|
||||||
const passport = require('passport');
|
|
||||||
|
|
||||||
|
|
||||||
const config = require('../config');
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
const { parse } = require('json2csv');
|
|
||||||
|
|
||||||
const { checkCrudPermissions } = require('../middlewares/check-permissions');
|
|
||||||
|
|
||||||
router.use(checkCrudPermissions('cart'));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* components:
|
|
||||||
* schemas:
|
|
||||||
* Cart:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* tags:
|
|
||||||
* name: Cart
|
|
||||||
* description: The Cart managing API
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart:
|
|
||||||
* post:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Add new item
|
|
||||||
* description: Add new item
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* data:
|
|
||||||
* description: Data of the updated item
|
|
||||||
* type: object
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The item was successfully added
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 405:
|
|
||||||
* description: Invalid input data
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.post(
|
|
||||||
'/',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const referer =
|
|
||||||
req.headers.referer ||
|
|
||||||
`${req.protocol}://${req.hostname}${req.originalUrl}`;
|
|
||||||
const link = new URL(referer);
|
|
||||||
await CartService.create(req.body.data, req.currentUser, true, link.host);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/budgets/bulk-import:
|
|
||||||
* post:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Bulk import items
|
|
||||||
* description: Bulk import items
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* data:
|
|
||||||
* description: Data of the updated items
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The items were successfully imported
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 405:
|
|
||||||
* description: Invalid input data
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
router.post(
|
|
||||||
'/bulk-import',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const referer =
|
|
||||||
req.headers.referer ||
|
|
||||||
`${req.protocol}://${req.hostname}${req.originalUrl}`;
|
|
||||||
const link = new URL(referer);
|
|
||||||
await CartService.bulkImport(req, res, true, link.host);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/{id}:
|
|
||||||
* put:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Update the data of the selected item
|
|
||||||
* description: Update the data of the selected item
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* description: Item ID to update
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* requestBody:
|
|
||||||
* description: Set new item data
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* id:
|
|
||||||
* description: ID of the updated item
|
|
||||||
* type: string
|
|
||||||
* data:
|
|
||||||
* description: Data of the updated item
|
|
||||||
* type: object
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* required:
|
|
||||||
* - id
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The item data was successfully updated
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 400:
|
|
||||||
* description: Invalid ID supplied
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Item not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.put(
|
|
||||||
'/:id',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
await CartService.update(req.body.data, req.body.id, req.currentUser);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/{id}:
|
|
||||||
* delete:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Delete the selected item
|
|
||||||
* description: Delete the selected item
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* description: Item ID to delete
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The item was successfully deleted
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 400:
|
|
||||||
* description: Invalid ID supplied
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Item not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.delete(
|
|
||||||
'/:id',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
await CartService.remove(req.params.id, req.currentUser);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/deleteByIds:
|
|
||||||
* post:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Delete the selected item list
|
|
||||||
* description: Delete the selected item list
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* ids:
|
|
||||||
* description: IDs of the updated items
|
|
||||||
* type: array
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The items was successfully deleted
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Items not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.post(
|
|
||||||
'/deleteByIds',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
await CartService.deleteByIds(req.body.data, req.currentUser);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Get all cart
|
|
||||||
* description: Get all cart
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Cart list successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Data not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const filetype = req.query.filetype;
|
|
||||||
|
|
||||||
const globalAccess = req.currentUser.app_role.globalAccess;
|
|
||||||
|
|
||||||
const currentUser = req.currentUser;
|
|
||||||
const payload = await CartDBApi.findAll(req.query, globalAccess, {
|
|
||||||
currentUser,
|
|
||||||
});
|
|
||||||
if (filetype && filetype === 'csv') {
|
|
||||||
const fields = ['id'];
|
|
||||||
const opts = { fields };
|
|
||||||
try {
|
|
||||||
const csv = parse(payload.rows, opts);
|
|
||||||
res.status(200).attachment(csv);
|
|
||||||
res.send(csv);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/count:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Count all cart
|
|
||||||
* description: Count all cart
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Cart count successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Data not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/count',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const globalAccess = req.currentUser.app_role.globalAccess;
|
|
||||||
|
|
||||||
const currentUser = req.currentUser;
|
|
||||||
const payload = await CartDBApi.findAll(req.query, globalAccess, {
|
|
||||||
countOnly: true,
|
|
||||||
currentUser,
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/autocomplete:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Find all cart that match search criteria
|
|
||||||
* description: Find all cart that match search criteria
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Cart list successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Data not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get('/autocomplete', async (req, res) => {
|
|
||||||
const globalAccess = req.currentUser.app_role.globalAccess;
|
|
||||||
|
|
||||||
const organizationId = req.currentUser.organization?.id;
|
|
||||||
|
|
||||||
const payload = await CartDBApi.findAllAutocomplete(
|
|
||||||
req.query.query,
|
|
||||||
req.query.limit,
|
|
||||||
req.query.offset,
|
|
||||||
globalAccess,
|
|
||||||
organizationId,
|
|
||||||
);
|
|
||||||
|
|
||||||
res.status(200).send(payload);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/{id}:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Cart]
|
|
||||||
* summary: Get selected item
|
|
||||||
* description: Get selected item
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* description: ID of item to get
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Selected item successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Cart"
|
|
||||||
* 400:
|
|
||||||
* description: Invalid ID supplied
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Item not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/:id',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const payload = await CartDBApi.findBy({ id: req.params.id });
|
|
||||||
|
|
||||||
// Checkout endpoint
|
|
||||||
router.post(
|
|
||||||
'/checkout',
|
|
||||||
passport.authenticate('jwt', { session: false }),
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const currentUser = req.currentUser;
|
|
||||||
const carts = await CartDBApi.findAll({ user: currentUser.id }, null, { currentUser });
|
|
||||||
if (!carts.rows.length) {
|
|
||||||
return res.status(400).json({ message: 'Cart is empty.' });
|
|
||||||
}
|
|
||||||
const cart = carts.rows[0];
|
|
||||||
const items = await db.cartitem.findAll({ where: { cartId: cart.id } });
|
|
||||||
const amount = items.reduce((sum, item) => sum + item.quantity * item.unitprice, 0);
|
|
||||||
const chargeData = {
|
|
||||||
amount,
|
|
||||||
currency: config.tap.currency || 'SAR',
|
|
||||||
threeDSecure: config.tap.force3DSecure,
|
|
||||||
capture: config.tap.capture,
|
|
||||||
description: `Charge for cart ${cart.id}`,
|
|
||||||
reference: {
|
|
||||||
track: uuidv4(),
|
|
||||||
payment: uuidv4(),
|
|
||||||
order: cart.id,
|
|
||||||
},
|
|
||||||
post: { url: config.tap.webhookUrl },
|
|
||||||
redirect: { url: config.tap.successUrl },
|
|
||||||
customer: {
|
|
||||||
id: currentUser.id,
|
|
||||||
email: currentUser.email,
|
|
||||||
first_name: currentUser.firstName,
|
|
||||||
last_name: currentUser.lastName,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const charge = await tapService.createCharge(chargeData);
|
|
||||||
res.json({ charge });
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.use('/', require('../helpers').commonErrorHandler);
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@ -28,9 +28,6 @@ router.use(checkCrudPermissions('tours'));
|
|||||||
* description:
|
* description:
|
||||||
* type: string
|
* type: string
|
||||||
* default: description
|
* default: description
|
||||||
* image_url:
|
|
||||||
* type: string
|
|
||||||
* default: image_url
|
|
||||||
|
|
||||||
* price:
|
* price:
|
||||||
* type: integer
|
* type: integer
|
||||||
@ -319,7 +316,6 @@ router.get(
|
|||||||
'id',
|
'id',
|
||||||
'title',
|
'title',
|
||||||
'description',
|
'description',
|
||||||
'image_url',
|
|
||||||
|
|
||||||
'price',
|
'price',
|
||||||
'start_date',
|
'start_date',
|
||||||
|
|||||||
@ -1,51 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const qs = require('qs');
|
|
||||||
const config = require('../config');
|
|
||||||
|
|
||||||
let accessToken = null;
|
|
||||||
let tokenExpiresAt = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtain or refresh Amadeus OAuth token
|
|
||||||
*/
|
|
||||||
async function getAccessToken() {
|
|
||||||
const now = Date.now();
|
|
||||||
if (accessToken && now < tokenExpiresAt) {
|
|
||||||
return accessToken;
|
|
||||||
}
|
|
||||||
const tokenUrl = `${config.amadeus.baseURL}/v1/security/oauth2/token`;
|
|
||||||
const data = qs.stringify({
|
|
||||||
grant_type: 'client_credentials',
|
|
||||||
client_id: config.amadeus.clientId,
|
|
||||||
client_secret: config.amadeus.clientSecret,
|
|
||||||
});
|
|
||||||
const resp = await axios.post(tokenUrl, data, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
accessToken = resp.data.access_token;
|
|
||||||
// expires_in is seconds
|
|
||||||
tokenExpiresAt = now + resp.data.expires_in * 1000 - 60000; // refresh 1 min early
|
|
||||||
return accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search flights via Amadeus
|
|
||||||
* @param {Object} params originLocationCode, destinationLocationCode, departureDate, adults, currency
|
|
||||||
*/
|
|
||||||
async function searchFlights(params) {
|
|
||||||
const token = await getAccessToken();
|
|
||||||
const url = `${config.amadeus.baseURL}/v2/shopping/flight-offers`;
|
|
||||||
const resp = await axios.get(url, {
|
|
||||||
params: params,
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return resp.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
searchFlights,
|
|
||||||
};
|
|
||||||
@ -1,114 +0,0 @@
|
|||||||
const db = require('../db/models');
|
|
||||||
const CartDBApi = require('../db/api/cart');
|
|
||||||
const processFile = require('../middlewares/upload');
|
|
||||||
const ValidationError = require('./notifications/errors/validation');
|
|
||||||
const csv = require('csv-parser');
|
|
||||||
const axios = require('axios');
|
|
||||||
const config = require('../config');
|
|
||||||
const stream = require('stream');
|
|
||||||
|
|
||||||
module.exports = class CartService {
|
|
||||||
static async create(data, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await CartDBApi.create(data, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async bulkImport(req, res, sendInvitationEmails = true, host) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await processFile(req, res);
|
|
||||||
const bufferStream = new stream.PassThrough();
|
|
||||||
const results = [];
|
|
||||||
|
|
||||||
await bufferStream.end(Buffer.from(req.file.buffer, 'utf-8')); // convert Buffer to Stream
|
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
bufferStream
|
|
||||||
.pipe(csv())
|
|
||||||
.on('data', (data) => results.push(data))
|
|
||||||
.on('end', async () => {
|
|
||||||
console.log('CSV results', results);
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.on('error', (error) => reject(error));
|
|
||||||
});
|
|
||||||
|
|
||||||
await CartDBApi.bulkImport(results, {
|
|
||||||
transaction,
|
|
||||||
ignoreDuplicates: true,
|
|
||||||
validate: true,
|
|
||||||
currentUser: req.currentUser,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async update(data, id, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
let cart = await CartDBApi.findBy({ id }, { transaction });
|
|
||||||
|
|
||||||
if (!cart) {
|
|
||||||
throw new ValidationError('cartNotFound');
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedCart = await CartDBApi.update(id, data, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
return updatedCart;
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async deleteByIds(ids, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await CartDBApi.deleteByIds(ids, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async remove(id, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await CartDBApi.remove(id, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -45,7 +45,7 @@ module.exports = class SearchService {
|
|||||||
|
|
||||||
agents: ['name'],
|
agents: ['name'],
|
||||||
|
|
||||||
tours: ['title', 'description', 'image_url'],
|
tours: ['title', 'description'],
|
||||||
|
|
||||||
agencies: ['name'],
|
agencies: ['name'],
|
||||||
};
|
};
|
||||||
@ -53,8 +53,6 @@ module.exports = class SearchService {
|
|||||||
agents: ['commission_rate'],
|
agents: ['commission_rate'],
|
||||||
|
|
||||||
tours: ['price'],
|
tours: ['price'],
|
||||||
|
|
||||||
cartitem: ['quantity', 'unitprice'],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let allFoundRecords = [];
|
let allFoundRecords = [];
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const config = require('../config');
|
|
||||||
|
|
||||||
// Initialize Tap API client
|
|
||||||
const tapClient = axios.create({
|
|
||||||
baseURL: config.tap.baseURL,
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${config.tap.secretKey}`,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a charge via Tap Payments
|
|
||||||
* @param {Object} data - payload for /v2/charges
|
|
||||||
*/
|
|
||||||
async function createCharge(data) {
|
|
||||||
const resp = await tapClient.post('/v2/charges', data);
|
|
||||||
return resp.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { createCharge };
|
|
||||||
@ -1 +0,0 @@
|
|||||||
{}
|
|
||||||
@ -1,107 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import ImageField from '../ImageField';
|
|
||||||
import ListActionsPopover from '../ListActionsPopover';
|
|
||||||
import { useAppSelector } from '../../stores/hooks';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import { Pagination } from '../Pagination';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import LoadingSpinner from '../LoadingSpinner';
|
|
||||||
import Link from 'next/link';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
cart: any[];
|
|
||||||
loading: boolean;
|
|
||||||
onDelete: (id: string) => void;
|
|
||||||
currentPage: number;
|
|
||||||
numPages: number;
|
|
||||||
onPageChange: (page: number) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CardCart = ({
|
|
||||||
cart,
|
|
||||||
loading,
|
|
||||||
onDelete,
|
|
||||||
currentPage,
|
|
||||||
numPages,
|
|
||||||
onPageChange,
|
|
||||||
}: Props) => {
|
|
||||||
const asideScrollbarsStyle = useAppSelector(
|
|
||||||
(state) => state.style.asideScrollbarsStyle,
|
|
||||||
);
|
|
||||||
const bgColor = useAppSelector((state) => state.style.cardsColor);
|
|
||||||
const darkMode = useAppSelector((state) => state.style.darkMode);
|
|
||||||
const corners = useAppSelector((state) => state.style.corners);
|
|
||||||
const focusRing = useAppSelector((state) => state.style.focusRingColor);
|
|
||||||
|
|
||||||
const currentUser = useAppSelector((state) => state.auth.currentUser);
|
|
||||||
const hasUpdatePermission = hasPermission(currentUser, 'UPDATE_CART');
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={'p-4'}>
|
|
||||||
{loading && <LoadingSpinner />}
|
|
||||||
<ul
|
|
||||||
role='list'
|
|
||||||
className='grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-3 2xl:grid-cols-4 xl:gap-x-8'
|
|
||||||
>
|
|
||||||
{!loading &&
|
|
||||||
cart.map((item, index) => (
|
|
||||||
<li
|
|
||||||
key={item.id}
|
|
||||||
className={`overflow-hidden ${
|
|
||||||
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
|
||||||
} border ${focusRing} border-gray-200 dark:border-dark-700 ${
|
|
||||||
darkMode ? 'aside-scrollbars-[slate]' : asideScrollbarsStyle
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={`flex items-center ${bgColor} p-6 gap-x-4 border-b border-gray-900/5 bg-gray-50 dark:bg-dark-800 relative`}
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
href={`/cart/cart-view/?id=${item.id}`}
|
|
||||||
className='text-lg font-bold leading-6 line-clamp-1'
|
|
||||||
>
|
|
||||||
{item.id}
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
<div className='ml-auto '>
|
|
||||||
<ListActionsPopover
|
|
||||||
onDelete={onDelete}
|
|
||||||
itemId={item.id}
|
|
||||||
pathEdit={`/cart/cart-edit/?id=${item.id}`}
|
|
||||||
pathView={`/cart/cart-view/?id=${item.id}`}
|
|
||||||
hasUpdatePermission={hasUpdatePermission}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<dl className='divide-y divide-gray-600 dark:divide-dark-700 px-6 py-4 text-sm leading-6 h-64 overflow-y-auto'>
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>User</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{dataFormatter.usersOneListFormatter(item.user)}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
</dl>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
{!loading && cart.length === 0 && (
|
|
||||||
<div className='col-span-full flex items-center justify-center h-40'>
|
|
||||||
<p className=''>No data to display</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
<div className={'flex items-center justify-center my-6'}>
|
|
||||||
<Pagination
|
|
||||||
currentPage={currentPage}
|
|
||||||
numPages={numPages}
|
|
||||||
setCurrentPage={onPageChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CardCart;
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import CardBox from '../CardBox';
|
|
||||||
import ImageField from '../ImageField';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import ListActionsPopover from '../ListActionsPopover';
|
|
||||||
import { useAppSelector } from '../../stores/hooks';
|
|
||||||
import { Pagination } from '../Pagination';
|
|
||||||
import LoadingSpinner from '../LoadingSpinner';
|
|
||||||
import Link from 'next/link';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
cart: any[];
|
|
||||||
loading: boolean;
|
|
||||||
onDelete: (id: string) => void;
|
|
||||||
currentPage: number;
|
|
||||||
numPages: number;
|
|
||||||
onPageChange: (page: number) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const ListCart = ({
|
|
||||||
cart,
|
|
||||||
loading,
|
|
||||||
onDelete,
|
|
||||||
currentPage,
|
|
||||||
numPages,
|
|
||||||
onPageChange,
|
|
||||||
}: Props) => {
|
|
||||||
const currentUser = useAppSelector((state) => state.auth.currentUser);
|
|
||||||
const hasUpdatePermission = hasPermission(currentUser, 'UPDATE_CART');
|
|
||||||
|
|
||||||
const corners = useAppSelector((state) => state.style.corners);
|
|
||||||
const bgColor = useAppSelector((state) => state.style.cardsColor);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className='relative overflow-x-auto p-4 space-y-4'>
|
|
||||||
{loading && <LoadingSpinner />}
|
|
||||||
{!loading &&
|
|
||||||
cart.map((item) => (
|
|
||||||
<div key={item.id}>
|
|
||||||
<CardBox hasTable isList className={'rounded shadow-none'}>
|
|
||||||
<div
|
|
||||||
className={`flex ${bgColor} ${
|
|
||||||
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
|
||||||
} dark:bg-dark-900 border border-gray-600 items-center overflow-hidden`}
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
href={`/cart/cart-view/?id=${item.id}`}
|
|
||||||
className={
|
|
||||||
'flex-1 px-4 py-6 h-24 flex divide-x-2 divide-gray-600 items-center overflow-hidden`}> dark:divide-dark-700 overflow-x-auto'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>User</p>
|
|
||||||
<p className={'line-clamp-2'}>
|
|
||||||
{dataFormatter.usersOneListFormatter(item.user)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
<ListActionsPopover
|
|
||||||
onDelete={onDelete}
|
|
||||||
itemId={item.id}
|
|
||||||
pathEdit={`/cart/cart-edit/?id=${item.id}`}
|
|
||||||
pathView={`/cart/cart-view/?id=${item.id}`}
|
|
||||||
hasUpdatePermission={hasUpdatePermission}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
{!loading && cart.length === 0 && (
|
|
||||||
<div className='col-span-full flex items-center justify-center h-40'>
|
|
||||||
<p className=''>No data to display</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className={'flex items-center justify-center my-6'}>
|
|
||||||
<Pagination
|
|
||||||
currentPage={currentPage}
|
|
||||||
numPages={numPages}
|
|
||||||
setCurrentPage={onPageChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ListCart;
|
|
||||||
@ -1,484 +0,0 @@
|
|||||||
import React, { useEffect, useState, useMemo } from 'react';
|
|
||||||
import { createPortal } from 'react-dom';
|
|
||||||
import { ToastContainer, toast } from 'react-toastify';
|
|
||||||
import BaseButton from '../BaseButton';
|
|
||||||
import CardBoxModal from '../CardBoxModal';
|
|
||||||
import CardBox from '../CardBox';
|
|
||||||
import {
|
|
||||||
fetch,
|
|
||||||
update,
|
|
||||||
deleteItem,
|
|
||||||
setRefetch,
|
|
||||||
deleteItemsByIds,
|
|
||||||
} from '../../stores/cart/cartSlice';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import { DataGrid, GridColDef } from '@mui/x-data-grid';
|
|
||||||
import { loadColumns } from './configureCartCols';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import { dataGridStyles } from '../../styles';
|
|
||||||
|
|
||||||
const perPage = 10;
|
|
||||||
|
|
||||||
const TableSampleCart = ({
|
|
||||||
filterItems,
|
|
||||||
setFilterItems,
|
|
||||||
filters,
|
|
||||||
showGrid,
|
|
||||||
}) => {
|
|
||||||
const notify = (type, msg) => toast(msg, { type, position: 'bottom-center' });
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const pagesList = [];
|
|
||||||
const [id, setId] = useState(null);
|
|
||||||
const [currentPage, setCurrentPage] = useState(0);
|
|
||||||
const [filterRequest, setFilterRequest] = React.useState('');
|
|
||||||
const [columns, setColumns] = useState<GridColDef[]>([]);
|
|
||||||
const [selectedRows, setSelectedRows] = useState([]);
|
|
||||||
const [sortModel, setSortModel] = useState([
|
|
||||||
{
|
|
||||||
field: '',
|
|
||||||
sort: 'desc',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const {
|
|
||||||
cart,
|
|
||||||
loading,
|
|
||||||
count,
|
|
||||||
notify: cartNotify,
|
|
||||||
refetch,
|
|
||||||
} = useAppSelector((state) => state.cart);
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
const focusRing = useAppSelector((state) => state.style.focusRingColor);
|
|
||||||
const bgColor = useAppSelector((state) => state.style.bgLayoutColor);
|
|
||||||
const corners = useAppSelector((state) => state.style.corners);
|
|
||||||
const numPages =
|
|
||||||
Math.floor(count / perPage) === 0 ? 1 : Math.ceil(count / perPage);
|
|
||||||
for (let i = 0; i < numPages; i++) {
|
|
||||||
pagesList.push(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadData = async (page = currentPage, request = filterRequest) => {
|
|
||||||
if (page !== currentPage) setCurrentPage(page);
|
|
||||||
if (request !== filterRequest) setFilterRequest(request);
|
|
||||||
const { sort, field } = sortModel[0];
|
|
||||||
|
|
||||||
const query = `?page=${page}&limit=${perPage}${request}&sort=${sort}&field=${field}`;
|
|
||||||
dispatch(fetch({ limit: perPage, page, query }));
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (cartNotify.showNotification) {
|
|
||||||
notify(cartNotify.typeNotification, cartNotify.textNotification);
|
|
||||||
}
|
|
||||||
}, [cartNotify.showNotification]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!currentUser) return;
|
|
||||||
loadData();
|
|
||||||
}, [sortModel, currentUser]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (refetch) {
|
|
||||||
loadData(0);
|
|
||||||
dispatch(setRefetch(false));
|
|
||||||
}
|
|
||||||
}, [refetch, dispatch]);
|
|
||||||
|
|
||||||
const [isModalInfoActive, setIsModalInfoActive] = useState(false);
|
|
||||||
const [isModalTrashActive, setIsModalTrashActive] = useState(false);
|
|
||||||
|
|
||||||
const handleModalAction = () => {
|
|
||||||
setIsModalInfoActive(false);
|
|
||||||
setIsModalTrashActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteModalAction = (id: string) => {
|
|
||||||
setId(id);
|
|
||||||
setIsModalTrashActive(true);
|
|
||||||
};
|
|
||||||
const handleDeleteAction = async () => {
|
|
||||||
if (id) {
|
|
||||||
await dispatch(deleteItem(id));
|
|
||||||
await loadData(0);
|
|
||||||
setIsModalTrashActive(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateFilterRequests = useMemo(() => {
|
|
||||||
let request = '&';
|
|
||||||
filterItems.forEach((item) => {
|
|
||||||
const isRangeFilter = filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title === item.fields.selectedField &&
|
|
||||||
(filter.number || filter.date),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isRangeFilter) {
|
|
||||||
const from = item.fields.filterValueFrom;
|
|
||||||
const to = item.fields.filterValueTo;
|
|
||||||
if (from) {
|
|
||||||
request += `${item.fields.selectedField}Range=${from}&`;
|
|
||||||
}
|
|
||||||
if (to) {
|
|
||||||
request += `${item.fields.selectedField}Range=${to}&`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const value = item.fields.filterValue;
|
|
||||||
if (value) {
|
|
||||||
request += `${item.fields.selectedField}=${value}&`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return request;
|
|
||||||
}, [filterItems, filters]);
|
|
||||||
|
|
||||||
const deleteFilter = (value) => {
|
|
||||||
const newItems = filterItems.filter((item) => item.id !== value);
|
|
||||||
|
|
||||||
if (newItems.length) {
|
|
||||||
setFilterItems(newItems);
|
|
||||||
} else {
|
|
||||||
loadData(0, '');
|
|
||||||
|
|
||||||
setFilterItems(newItems);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
|
||||||
loadData(0, generateFilterRequests);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (id) => (e) => {
|
|
||||||
const value = e.target.value;
|
|
||||||
const name = e.target.name;
|
|
||||||
|
|
||||||
setFilterItems(
|
|
||||||
filterItems.map((item) => {
|
|
||||||
if (item.id !== id) return item;
|
|
||||||
if (name === 'selectedField') return { id, fields: { [name]: value } };
|
|
||||||
|
|
||||||
return { id, fields: { ...item.fields, [name]: value } };
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleReset = () => {
|
|
||||||
setFilterItems([]);
|
|
||||||
loadData(0, '');
|
|
||||||
};
|
|
||||||
|
|
||||||
const onPageChange = (page: number) => {
|
|
||||||
loadData(page);
|
|
||||||
setCurrentPage(page);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!currentUser) return;
|
|
||||||
|
|
||||||
loadColumns(handleDeleteModalAction, `cart`, currentUser).then((newCols) =>
|
|
||||||
setColumns(newCols),
|
|
||||||
);
|
|
||||||
}, [currentUser]);
|
|
||||||
|
|
||||||
const handleTableSubmit = async (id: string, data) => {
|
|
||||||
if (!_.isEmpty(data)) {
|
|
||||||
await dispatch(update({ id, data }))
|
|
||||||
.unwrap()
|
|
||||||
.then((res) => res)
|
|
||||||
.catch((err) => {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDeleteRows = async (selectedRows) => {
|
|
||||||
await dispatch(deleteItemsByIds(selectedRows));
|
|
||||||
await loadData(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const controlClasses =
|
|
||||||
'w-full py-2 px-2 my-2 rounded dark:placeholder-gray-400 ' +
|
|
||||||
` ${bgColor} ${focusRing} ${corners} ` +
|
|
||||||
'dark:bg-slate-800 border';
|
|
||||||
|
|
||||||
const dataGrid = (
|
|
||||||
<div className='relative overflow-x-auto'>
|
|
||||||
<DataGrid
|
|
||||||
autoHeight
|
|
||||||
rowHeight={64}
|
|
||||||
sx={dataGridStyles}
|
|
||||||
className={'datagrid--table'}
|
|
||||||
getRowClassName={() => `datagrid--row`}
|
|
||||||
rows={cart ?? []}
|
|
||||||
columns={columns}
|
|
||||||
initialState={{
|
|
||||||
pagination: {
|
|
||||||
paginationModel: {
|
|
||||||
pageSize: 10,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
disableRowSelectionOnClick
|
|
||||||
onProcessRowUpdateError={(params) => {
|
|
||||||
console.log('Error', params);
|
|
||||||
}}
|
|
||||||
processRowUpdate={async (newRow, oldRow) => {
|
|
||||||
const data = dataFormatter.dataGridEditFormatter(newRow);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await handleTableSubmit(newRow.id, data);
|
|
||||||
return newRow;
|
|
||||||
} catch {
|
|
||||||
return oldRow;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
sortingMode={'server'}
|
|
||||||
checkboxSelection
|
|
||||||
onRowSelectionModelChange={(ids) => {
|
|
||||||
setSelectedRows(ids);
|
|
||||||
}}
|
|
||||||
onSortModelChange={(params) => {
|
|
||||||
params.length
|
|
||||||
? setSortModel(params)
|
|
||||||
: setSortModel([{ field: '', sort: 'desc' }]);
|
|
||||||
}}
|
|
||||||
rowCount={count}
|
|
||||||
pageSizeOptions={[10]}
|
|
||||||
paginationMode={'server'}
|
|
||||||
loading={loading}
|
|
||||||
onPaginationModelChange={(params) => {
|
|
||||||
onPageChange(params.page);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{filterItems && Array.isArray(filterItems) && filterItems.length ? (
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
initialValues={{
|
|
||||||
checkboxes: ['lorem'],
|
|
||||||
switches: ['lorem'],
|
|
||||||
radio: 'lorem',
|
|
||||||
}}
|
|
||||||
onSubmit={() => null}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<>
|
|
||||||
{filterItems &&
|
|
||||||
filterItems.map((filterItem) => {
|
|
||||||
return (
|
|
||||||
<div key={filterItem.id} className='flex mb-4'>
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
Filter
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='selectedField'
|
|
||||||
id='selectedField'
|
|
||||||
component='select'
|
|
||||||
value={filterItem?.fields?.selectedField || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
>
|
|
||||||
{filters.map((selectOption) => (
|
|
||||||
<option
|
|
||||||
key={selectOption.title}
|
|
||||||
value={`${selectOption.title}`}
|
|
||||||
>
|
|
||||||
{selectOption.label}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</Field>
|
|
||||||
</div>
|
|
||||||
{filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title === filterItem?.fields?.selectedField,
|
|
||||||
)?.type === 'enum' ? (
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className='text-gray-500 font-bold'>Value</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValue'
|
|
||||||
id='filterValue'
|
|
||||||
component='select'
|
|
||||||
value={filterItem?.fields?.filterValue || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
>
|
|
||||||
<option value=''>Select Value</option>
|
|
||||||
{filters
|
|
||||||
.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title ===
|
|
||||||
filterItem?.fields?.selectedField,
|
|
||||||
)
|
|
||||||
?.options?.map((option) => (
|
|
||||||
<option key={option} value={option}>
|
|
||||||
{option}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</Field>
|
|
||||||
</div>
|
|
||||||
) : filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title ===
|
|
||||||
filterItem?.fields?.selectedField,
|
|
||||||
)?.number ? (
|
|
||||||
<div className='flex flex-row w-full mr-3'>
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
From
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueFrom'
|
|
||||||
placeholder='From'
|
|
||||||
id='filterValueFrom'
|
|
||||||
value={
|
|
||||||
filterItem?.fields?.filterValueFrom || ''
|
|
||||||
}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='flex flex-col w-full'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
To
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueTo'
|
|
||||||
placeholder='to'
|
|
||||||
id='filterValueTo'
|
|
||||||
value={filterItem?.fields?.filterValueTo || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title ===
|
|
||||||
filterItem?.fields?.selectedField,
|
|
||||||
)?.date ? (
|
|
||||||
<div className='flex flex-row w-full mr-3'>
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
From
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueFrom'
|
|
||||||
placeholder='From'
|
|
||||||
id='filterValueFrom'
|
|
||||||
type='datetime-local'
|
|
||||||
value={
|
|
||||||
filterItem?.fields?.filterValueFrom || ''
|
|
||||||
}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='flex flex-col w-full'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
To
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueTo'
|
|
||||||
placeholder='to'
|
|
||||||
id='filterValueTo'
|
|
||||||
type='datetime-local'
|
|
||||||
value={filterItem?.fields?.filterValueTo || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
Contains
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValue'
|
|
||||||
placeholder='Contained'
|
|
||||||
id='filterValue'
|
|
||||||
value={filterItem?.fields?.filterValue || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className='flex flex-col'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
Action
|
|
||||||
</div>
|
|
||||||
<BaseButton
|
|
||||||
className='my-2'
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
label='Delete'
|
|
||||||
onClick={() => {
|
|
||||||
deleteFilter(filterItem.id);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
<div className='flex'>
|
|
||||||
<BaseButton
|
|
||||||
className='my-2 mr-3'
|
|
||||||
type='submit'
|
|
||||||
color='info'
|
|
||||||
label='Apply'
|
|
||||||
onClick={handleSubmit}
|
|
||||||
/>
|
|
||||||
<BaseButton
|
|
||||||
className='my-2'
|
|
||||||
type='reset'
|
|
||||||
color='info'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={handleReset}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
) : null}
|
|
||||||
<CardBoxModal
|
|
||||||
title='Please confirm'
|
|
||||||
buttonColor='info'
|
|
||||||
buttonLabel={loading ? 'Deleting...' : 'Confirm'}
|
|
||||||
isActive={isModalTrashActive}
|
|
||||||
onConfirm={handleDeleteAction}
|
|
||||||
onCancel={handleModalAction}
|
|
||||||
>
|
|
||||||
<p>Are you sure you want to delete this item?</p>
|
|
||||||
</CardBoxModal>
|
|
||||||
|
|
||||||
{dataGrid}
|
|
||||||
|
|
||||||
{selectedRows.length > 0 &&
|
|
||||||
createPortal(
|
|
||||||
<BaseButton
|
|
||||||
className='me-4'
|
|
||||||
color='danger'
|
|
||||||
label={`Delete ${selectedRows.length === 1 ? 'Row' : 'Rows'}`}
|
|
||||||
onClick={() => onDeleteRows(selectedRows)}
|
|
||||||
/>,
|
|
||||||
document.getElementById('delete-rows-button'),
|
|
||||||
)}
|
|
||||||
<ToastContainer />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default TableSampleCart;
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import BaseIcon from '../BaseIcon';
|
|
||||||
import { mdiEye, mdiTrashCan, mdiPencilOutline } from '@mdi/js';
|
|
||||||
import axios from 'axios';
|
|
||||||
import {
|
|
||||||
GridActionsCellItem,
|
|
||||||
GridRowParams,
|
|
||||||
GridValueGetterParams,
|
|
||||||
} from '@mui/x-data-grid';
|
|
||||||
import ImageField from '../ImageField';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import DataGridMultiSelect from '../DataGridMultiSelect';
|
|
||||||
import ListActionsPopover from '../ListActionsPopover';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
type Params = (id: string) => void;
|
|
||||||
|
|
||||||
export const loadColumns = async (
|
|
||||||
onDelete: Params,
|
|
||||||
entityName: string,
|
|
||||||
|
|
||||||
user,
|
|
||||||
) => {
|
|
||||||
async function callOptionsApi(entityName: string) {
|
|
||||||
if (!hasPermission(user, 'READ_' + entityName.toUpperCase())) return [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await axios(`/${entityName}/autocomplete?limit=100`);
|
|
||||||
return data.data;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasUpdatePermission = hasPermission(user, 'UPDATE_CART');
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
field: 'user',
|
|
||||||
headerName: 'User',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
sortable: false,
|
|
||||||
type: 'singleSelect',
|
|
||||||
getOptionValue: (value: any) => value?.id,
|
|
||||||
getOptionLabel: (value: any) => value?.label,
|
|
||||||
valueOptions: await callOptionsApi('users'),
|
|
||||||
valueGetter: (params: GridValueGetterParams) =>
|
|
||||||
params?.value?.id ?? params?.value,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'actions',
|
|
||||||
type: 'actions',
|
|
||||||
minWidth: 30,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
getActions: (params: GridRowParams) => {
|
|
||||||
return [
|
|
||||||
<div key={params?.row?.id}>
|
|
||||||
<ListActionsPopover
|
|
||||||
onDelete={onDelete}
|
|
||||||
itemId={params?.row?.id}
|
|
||||||
pathEdit={`/cart/cart-edit/?id=${params?.row?.id}`}
|
|
||||||
pathView={`/cart/cart-view/?id=${params?.row?.id}`}
|
|
||||||
hasUpdatePermission={hasUpdatePermission}
|
|
||||||
/>
|
|
||||||
</div>,
|
|
||||||
];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
@ -135,17 +135,6 @@ const CardTours = ({
|
|||||||
</div>
|
</div>
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Image url
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.image_url}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
</dl>
|
</dl>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -88,11 +88,6 @@ const ListTours = ({
|
|||||||
{dataFormatter.agenciesOneListFormatter(item.agency)}
|
{dataFormatter.agenciesOneListFormatter(item.agency)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Image url</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.image_url}</p>
|
|
||||||
</div>
|
|
||||||
</Link>
|
</Link>
|
||||||
<ListActionsPopover
|
<ListActionsPopover
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
|||||||
@ -128,18 +128,6 @@ export const loadColumns = async (
|
|||||||
params?.value?.id ?? params?.value,
|
params?.value?.id ?? params?.value,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
field: 'image_url',
|
|
||||||
headerName: 'Image url',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
field: 'actions',
|
field: 'actions',
|
||||||
type: 'actions',
|
type: 'actions',
|
||||||
|
|||||||
@ -17,9 +17,9 @@ export default function WebSiteHeader({ projectName }: WebSiteHeaderProps) {
|
|||||||
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
||||||
const borders = useAppSelector((state) => state.style.borders);
|
const borders = useAppSelector((state) => state.style.borders);
|
||||||
|
|
||||||
const style = HeaderStyle.PAGES_RIGHT;
|
const style = HeaderStyle.PAGES_LEFT;
|
||||||
|
|
||||||
const design = HeaderDesigns.DEFAULT_DESIGN;
|
const design = HeaderDesigns.DESIGN_DIVERSITY;
|
||||||
return (
|
return (
|
||||||
<header id='websiteHeader' className='overflow-hidden'>
|
<header id='websiteHeader' className='overflow-hidden'>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -73,14 +73,6 @@ const menuAside: MenuAsideItem[] = [
|
|||||||
icon: icon.mdiTable ?? icon.mdiTable,
|
icon: icon.mdiTable ?? icon.mdiTable,
|
||||||
permissions: 'READ_AGENCIES',
|
permissions: 'READ_AGENCIES',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
href: '/cart/cart-list',
|
|
||||||
label: 'Cart',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_CART',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
href: '/profile',
|
href: '/profile',
|
||||||
label: 'Profile',
|
label: 'Profile',
|
||||||
|
|||||||
@ -1,112 +0,0 @@
|
|||||||
import * as icon from '@mdi/js';
|
|
||||||
import { MenuAsideItem } from './interfaces';
|
|
||||||
|
|
||||||
const menuAside: MenuAsideItem[] = [
|
|
||||||
{
|
|
||||||
href: '/dashboard',
|
|
||||||
icon: icon.mdiViewDashboardOutline,
|
|
||||||
label: 'Dashboard',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
href: '/users/users-list',
|
|
||||||
label: 'Users',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiAccountGroup ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_USERS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/agents/agents-list',
|
|
||||||
label: 'Agents',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon:
|
|
||||||
'mdiAccountTie' in icon
|
|
||||||
? icon['mdiAccountTie' as keyof typeof icon]
|
|
||||||
: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_AGENTS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/bookings/bookings-list',
|
|
||||||
label: 'Bookings',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon:
|
|
||||||
'mdiCalendarCheck' in icon
|
|
||||||
? icon['mdiCalendarCheck' as keyof typeof icon]
|
|
||||||
: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_BOOKINGS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/tours/tours-list',
|
|
||||||
label: 'Tours',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon:
|
|
||||||
'mdiMapMarker' in icon
|
|
||||||
? icon['mdiMapMarker' as keyof typeof icon]
|
|
||||||
: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
|
|
||||||
{
|
|
||||||
href: '/flights-search',
|
|
||||||
label: 'Flights',
|
|
||||||
icon: icon.mdiAirplane,
|
|
||||||
},
|
|
||||||
|
|
||||||
permissions: 'READ_TOURS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/roles/roles-list',
|
|
||||||
label: 'Roles',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiShieldAccountVariantOutline ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_ROLES',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/permissions/permissions-list',
|
|
||||||
label: 'Permissions',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiShieldAccountOutline ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_PERMISSIONS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/agencies/agencies-list',
|
|
||||||
label: 'Agencies',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_AGENCIES',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/cart/cart-list',
|
|
||||||
label: 'Cart',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_CART',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/profile',
|
|
||||||
label: 'Profile',
|
|
||||||
icon: icon.mdiAccountCircle,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
href: '/home',
|
|
||||||
label: 'Home page',
|
|
||||||
icon: icon.mdiHome,
|
|
||||||
withDevider: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: '/api-docs',
|
|
||||||
target: '_blank',
|
|
||||||
label: 'Swagger API',
|
|
||||||
icon: icon.mdiFileCode,
|
|
||||||
permissions: 'READ_API_DOCS',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default menuAside;
|
|
||||||
@ -258,8 +258,6 @@ const AgenciesView = () => {
|
|||||||
<th>StartDate</th>
|
<th>StartDate</th>
|
||||||
|
|
||||||
<th>EndDate</th>
|
<th>EndDate</th>
|
||||||
|
|
||||||
<th>Image url</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -283,8 +281,6 @@ const AgenciesView = () => {
|
|||||||
<td data-label='end_date'>
|
<td data-label='end_date'>
|
||||||
{dataFormatter.dateTimeFormatter(item.end_date)}
|
{dataFormatter.dateTimeFormatter(item.end_date)}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td data-label='image_url'>{item.image_url}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -313,8 +309,6 @@ const AgenciesView = () => {
|
|||||||
<th>StartDate</th>
|
<th>StartDate</th>
|
||||||
|
|
||||||
<th>EndDate</th>
|
<th>EndDate</th>
|
||||||
|
|
||||||
<th>Image url</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -338,8 +332,6 @@ const AgenciesView = () => {
|
|||||||
<td data-label='end_date'>
|
<td data-label='end_date'>
|
||||||
{dataFormatter.dateTimeFormatter(item.end_date)}
|
{dataFormatter.dateTimeFormatter(item.end_date)}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td data-label='image_url'>{item.image_url}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -351,109 +343,6 @@ const AgenciesView = () => {
|
|||||||
</CardBox>
|
</CardBox>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
<>
|
|
||||||
<p className={'block font-bold mb-2'}>Cart agencies</p>
|
|
||||||
<CardBox
|
|
||||||
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
|
||||||
hasTable
|
|
||||||
>
|
|
||||||
<div className='overflow-x-auto'>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr></tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{agencies.cart_agencies &&
|
|
||||||
Array.isArray(agencies.cart_agencies) &&
|
|
||||||
agencies.cart_agencies.map((item: any) => (
|
|
||||||
<tr
|
|
||||||
key={item.id}
|
|
||||||
onClick={() =>
|
|
||||||
router.push(`/cart/cart-view/?id=${item.id}`)
|
|
||||||
}
|
|
||||||
></tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{!agencies?.cart_agencies?.length && (
|
|
||||||
<div className={'text-center py-4'}>No data</div>
|
|
||||||
)}
|
|
||||||
</CardBox>
|
|
||||||
</>
|
|
||||||
|
|
||||||
<>
|
|
||||||
<p className={'block font-bold mb-2'}>Cart Agency</p>
|
|
||||||
<CardBox
|
|
||||||
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
|
||||||
hasTable
|
|
||||||
>
|
|
||||||
<div className='overflow-x-auto'>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr></tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{agencies.cart_agency &&
|
|
||||||
Array.isArray(agencies.cart_agency) &&
|
|
||||||
agencies.cart_agency.map((item: any) => (
|
|
||||||
<tr
|
|
||||||
key={item.id}
|
|
||||||
onClick={() =>
|
|
||||||
router.push(`/cart/cart-view/?id=${item.id}`)
|
|
||||||
}
|
|
||||||
></tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{!agencies?.cart_agency?.length && (
|
|
||||||
<div className={'text-center py-4'}>No data</div>
|
|
||||||
)}
|
|
||||||
</CardBox>
|
|
||||||
</>
|
|
||||||
|
|
||||||
<>
|
|
||||||
<p className={'block font-bold mb-2'}>Cartitem agencies</p>
|
|
||||||
<CardBox
|
|
||||||
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
|
||||||
hasTable
|
|
||||||
>
|
|
||||||
<div className='overflow-x-auto'>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Quantity</th>
|
|
||||||
|
|
||||||
<th>Unitprice</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{agencies.cartitem_agencies &&
|
|
||||||
Array.isArray(agencies.cartitem_agencies) &&
|
|
||||||
agencies.cartitem_agencies.map((item: any) => (
|
|
||||||
<tr
|
|
||||||
key={item.id}
|
|
||||||
onClick={() =>
|
|
||||||
router.push(
|
|
||||||
`/cartitem/cartitem-view/?id=${item.id}`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<td data-label='quantity'>{item.quantity}</td>
|
|
||||||
|
|
||||||
<td data-label='unitprice'>{item.unitprice}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{!agencies?.cartitem_agencies?.length && (
|
|
||||||
<div className={'text-center py-4'}>No data</div>
|
|
||||||
)}
|
|
||||||
</CardBox>
|
|
||||||
</>
|
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
|
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
|||||||
@ -1,146 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import React, { ReactElement, useEffect, useState } from 'react';
|
|
||||||
import DatePicker from 'react-datepicker';
|
|
||||||
import 'react-datepicker/dist/react-datepicker.css';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import BaseButtons from '../../components/BaseButtons';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
||||||
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
||||||
import FormFilePicker from '../../components/FormFilePicker';
|
|
||||||
import FormImagePicker from '../../components/FormImagePicker';
|
|
||||||
import { SelectField } from '../../components/SelectField';
|
|
||||||
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
import { RichTextField } from '../../components/RichTextField';
|
|
||||||
|
|
||||||
import { update, fetch } from '../../stores/cart/cartSlice';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import ImageField from '../../components/ImageField';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const EditCart = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const initVals = {
|
|
||||||
agencies: null,
|
|
||||||
|
|
||||||
user: null,
|
|
||||||
};
|
|
||||||
const [initialValues, setInitialValues] = useState(initVals);
|
|
||||||
|
|
||||||
const { cart } = useAppSelector((state) => state.cart);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const { cartId } = router.query;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetch({ id: cartId }));
|
|
||||||
}, [cartId]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof cart === 'object') {
|
|
||||||
setInitialValues(cart);
|
|
||||||
}
|
|
||||||
}, [cart]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof cart === 'object') {
|
|
||||||
const newInitialVal = { ...initVals };
|
|
||||||
|
|
||||||
Object.keys(initVals).forEach((el) => (newInitialVal[el] = cart[el]));
|
|
||||||
|
|
||||||
setInitialValues(newInitialVal);
|
|
||||||
}
|
|
||||||
}, [cart]);
|
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
|
||||||
await dispatch(update({ id: cartId, data }));
|
|
||||||
await router.push('/cart/cart-list');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Edit cart')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title={'Edit cart'}
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
enableReinitialize
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={(values) => handleSubmit(values)}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<FormField label='agencies' labelFor='agencies'>
|
|
||||||
<Field
|
|
||||||
name='agencies'
|
|
||||||
id='agencies'
|
|
||||||
component={SelectField}
|
|
||||||
options={initialValues.agencies}
|
|
||||||
itemRef={'agencies'}
|
|
||||||
showField={'name'}
|
|
||||||
></Field>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='User' labelFor='user'>
|
|
||||||
<Field
|
|
||||||
name='user'
|
|
||||||
id='user'
|
|
||||||
component={SelectField}
|
|
||||||
options={initialValues.user}
|
|
||||||
itemRef={'users'}
|
|
||||||
showField={'firstName'}
|
|
||||||
></Field>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
<BaseButtons>
|
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
|
||||||
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
||||||
<BaseButton
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={() => router.push('/cart/cart-list')}
|
|
||||||
/>
|
|
||||||
</BaseButtons>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
EditCart.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'UPDATE_CART'}>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditCart;
|
|
||||||
@ -1,144 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import React, { ReactElement, useEffect, useState } from 'react';
|
|
||||||
import DatePicker from 'react-datepicker';
|
|
||||||
import 'react-datepicker/dist/react-datepicker.css';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import BaseButtons from '../../components/BaseButtons';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
||||||
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
||||||
import FormFilePicker from '../../components/FormFilePicker';
|
|
||||||
import FormImagePicker from '../../components/FormImagePicker';
|
|
||||||
import { SelectField } from '../../components/SelectField';
|
|
||||||
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
import { RichTextField } from '../../components/RichTextField';
|
|
||||||
|
|
||||||
import { update, fetch } from '../../stores/cart/cartSlice';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import ImageField from '../../components/ImageField';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const EditCartPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const initVals = {
|
|
||||||
agencies: null,
|
|
||||||
|
|
||||||
user: null,
|
|
||||||
};
|
|
||||||
const [initialValues, setInitialValues] = useState(initVals);
|
|
||||||
|
|
||||||
const { cart } = useAppSelector((state) => state.cart);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const { id } = router.query;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetch({ id: id }));
|
|
||||||
}, [id]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof cart === 'object') {
|
|
||||||
setInitialValues(cart);
|
|
||||||
}
|
|
||||||
}, [cart]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof cart === 'object') {
|
|
||||||
const newInitialVal = { ...initVals };
|
|
||||||
Object.keys(initVals).forEach((el) => (newInitialVal[el] = cart[el]));
|
|
||||||
setInitialValues(newInitialVal);
|
|
||||||
}
|
|
||||||
}, [cart]);
|
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
|
||||||
await dispatch(update({ id: id, data }));
|
|
||||||
await router.push('/cart/cart-list');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Edit cart')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title={'Edit cart'}
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
enableReinitialize
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={(values) => handleSubmit(values)}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<FormField label='agencies' labelFor='agencies'>
|
|
||||||
<Field
|
|
||||||
name='agencies'
|
|
||||||
id='agencies'
|
|
||||||
component={SelectField}
|
|
||||||
options={initialValues.agencies}
|
|
||||||
itemRef={'agencies'}
|
|
||||||
showField={'name'}
|
|
||||||
></Field>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='User' labelFor='user'>
|
|
||||||
<Field
|
|
||||||
name='user'
|
|
||||||
id='user'
|
|
||||||
component={SelectField}
|
|
||||||
options={initialValues.user}
|
|
||||||
itemRef={'users'}
|
|
||||||
showField={'firstName'}
|
|
||||||
></Field>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
<BaseButtons>
|
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
|
||||||
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
||||||
<BaseButton
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={() => router.push('/cart/cart-list')}
|
|
||||||
/>
|
|
||||||
</BaseButtons>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
EditCartPage.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'UPDATE_CART'}>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditCartPage;
|
|
||||||
@ -1,160 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { uniqueId } from 'lodash';
|
|
||||||
import React, { ReactElement, useState } from 'react';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
import TableCart from '../../components/Cart/TableCart';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import axios from 'axios';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import CardBoxModal from '../../components/CardBoxModal';
|
|
||||||
import DragDropFilePicker from '../../components/DragDropFilePicker';
|
|
||||||
import { setRefetch, uploadCsv } from '../../stores/cart/cartSlice';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const CartTablesPage = () => {
|
|
||||||
const [filterItems, setFilterItems] = useState([]);
|
|
||||||
const [csvFile, setCsvFile] = useState<File | null>(null);
|
|
||||||
const [isModalActive, setIsModalActive] = useState(false);
|
|
||||||
const [showTableView, setShowTableView] = useState(false);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const [filters] = useState([{ label: 'User', title: 'user' }]);
|
|
||||||
|
|
||||||
const hasCreatePermission =
|
|
||||||
currentUser && hasPermission(currentUser, 'CREATE_CART');
|
|
||||||
|
|
||||||
const addFilter = () => {
|
|
||||||
const newItem = {
|
|
||||||
id: uniqueId(),
|
|
||||||
fields: {
|
|
||||||
filterValue: '',
|
|
||||||
filterValueFrom: '',
|
|
||||||
filterValueTo: '',
|
|
||||||
selectedField: '',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
newItem.fields.selectedField = filters[0].title;
|
|
||||||
setFilterItems([...filterItems, newItem]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCartCSV = async () => {
|
|
||||||
const response = await axios({
|
|
||||||
url: '/cart?filetype=csv',
|
|
||||||
method: 'GET',
|
|
||||||
responseType: 'blob',
|
|
||||||
});
|
|
||||||
const type = response.headers['content-type'];
|
|
||||||
const blob = new Blob([response.data], { type: type });
|
|
||||||
const link = document.createElement('a');
|
|
||||||
link.href = window.URL.createObjectURL(blob);
|
|
||||||
link.download = 'cartCSV.csv';
|
|
||||||
link.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalConfirm = async () => {
|
|
||||||
if (!csvFile) return;
|
|
||||||
await dispatch(uploadCsv(csvFile));
|
|
||||||
dispatch(setRefetch(true));
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalCancel = () => {
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Cart')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title='Cart'
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox className='mb-6' cardBoxClassName='flex flex-wrap'>
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
href={'/cart/cart-new'}
|
|
||||||
color='info'
|
|
||||||
label='New Item'
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Filter'
|
|
||||||
onClick={addFilter}
|
|
||||||
/>
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Download CSV'
|
|
||||||
onClick={getCartCSV}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Upload CSV'
|
|
||||||
onClick={() => setIsModalActive(true)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className='md:inline-flex items-center ms-auto'>
|
|
||||||
<div id='delete-rows-button'></div>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
|
|
||||||
<CardBox className='mb-6' hasTable>
|
|
||||||
<TableCart
|
|
||||||
filterItems={filterItems}
|
|
||||||
setFilterItems={setFilterItems}
|
|
||||||
filters={filters}
|
|
||||||
showGrid={false}
|
|
||||||
/>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
<CardBoxModal
|
|
||||||
title='Upload CSV'
|
|
||||||
buttonColor='info'
|
|
||||||
buttonLabel={'Confirm'}
|
|
||||||
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
|
||||||
isActive={isModalActive}
|
|
||||||
onConfirm={onModalConfirm}
|
|
||||||
onCancel={onModalCancel}
|
|
||||||
>
|
|
||||||
<DragDropFilePicker
|
|
||||||
file={csvFile}
|
|
||||||
setFile={setCsvFile}
|
|
||||||
formats={'.csv'}
|
|
||||||
/>
|
|
||||||
</CardBoxModal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
CartTablesPage.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'READ_CART'}>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CartTablesPage;
|
|
||||||
@ -1,114 +0,0 @@
|
|||||||
import {
|
|
||||||
mdiAccount,
|
|
||||||
mdiChartTimelineVariant,
|
|
||||||
mdiMail,
|
|
||||||
mdiUpload,
|
|
||||||
} from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import React, { ReactElement } from 'react';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import BaseButtons from '../../components/BaseButtons';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
||||||
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
||||||
import FormFilePicker from '../../components/FormFilePicker';
|
|
||||||
import FormImagePicker from '../../components/FormImagePicker';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
|
|
||||||
import { SelectField } from '../../components/SelectField';
|
|
||||||
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
||||||
import { RichTextField } from '../../components/RichTextField';
|
|
||||||
|
|
||||||
import { create } from '../../stores/cart/cartSlice';
|
|
||||||
import { useAppDispatch } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import moment from 'moment';
|
|
||||||
|
|
||||||
const initialValues = {
|
|
||||||
agencies: '',
|
|
||||||
|
|
||||||
user: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
const CartNew = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
|
||||||
await dispatch(create(data));
|
|
||||||
await router.push('/cart/cart-list');
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('New Item')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title='New Item'
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={(values) => handleSubmit(values)}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<FormField label='agencies' labelFor='agencies'>
|
|
||||||
<Field
|
|
||||||
name='agencies'
|
|
||||||
id='agencies'
|
|
||||||
component={SelectField}
|
|
||||||
options={[]}
|
|
||||||
itemRef={'agencies'}
|
|
||||||
></Field>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='User' labelFor='user'>
|
|
||||||
<Field
|
|
||||||
name='user'
|
|
||||||
id='user'
|
|
||||||
component={SelectField}
|
|
||||||
options={[]}
|
|
||||||
itemRef={'users'}
|
|
||||||
></Field>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
<BaseButtons>
|
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
|
||||||
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
||||||
<BaseButton
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={() => router.push('/cart/cart-list')}
|
|
||||||
/>
|
|
||||||
</BaseButtons>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
CartNew.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'CREATE_CART'}>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CartNew;
|
|
||||||
@ -1,159 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { uniqueId } from 'lodash';
|
|
||||||
import React, { ReactElement, useState } from 'react';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
import TableCart from '../../components/Cart/TableCart';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import axios from 'axios';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import CardBoxModal from '../../components/CardBoxModal';
|
|
||||||
import DragDropFilePicker from '../../components/DragDropFilePicker';
|
|
||||||
import { setRefetch, uploadCsv } from '../../stores/cart/cartSlice';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const CartTablesPage = () => {
|
|
||||||
const [filterItems, setFilterItems] = useState([]);
|
|
||||||
const [csvFile, setCsvFile] = useState<File | null>(null);
|
|
||||||
const [isModalActive, setIsModalActive] = useState(false);
|
|
||||||
const [showTableView, setShowTableView] = useState(false);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const [filters] = useState([{ label: 'User', title: 'user' }]);
|
|
||||||
|
|
||||||
const hasCreatePermission =
|
|
||||||
currentUser && hasPermission(currentUser, 'CREATE_CART');
|
|
||||||
|
|
||||||
const addFilter = () => {
|
|
||||||
const newItem = {
|
|
||||||
id: uniqueId(),
|
|
||||||
fields: {
|
|
||||||
filterValue: '',
|
|
||||||
filterValueFrom: '',
|
|
||||||
filterValueTo: '',
|
|
||||||
selectedField: '',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
newItem.fields.selectedField = filters[0].title;
|
|
||||||
setFilterItems([...filterItems, newItem]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCartCSV = async () => {
|
|
||||||
const response = await axios({
|
|
||||||
url: '/cart?filetype=csv',
|
|
||||||
method: 'GET',
|
|
||||||
responseType: 'blob',
|
|
||||||
});
|
|
||||||
const type = response.headers['content-type'];
|
|
||||||
const blob = new Blob([response.data], { type: type });
|
|
||||||
const link = document.createElement('a');
|
|
||||||
link.href = window.URL.createObjectURL(blob);
|
|
||||||
link.download = 'cartCSV.csv';
|
|
||||||
link.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalConfirm = async () => {
|
|
||||||
if (!csvFile) return;
|
|
||||||
await dispatch(uploadCsv(csvFile));
|
|
||||||
dispatch(setRefetch(true));
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalCancel = () => {
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Cart')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title='Cart'
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox className='mb-6' cardBoxClassName='flex flex-wrap'>
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
href={'/cart/cart-new'}
|
|
||||||
color='info'
|
|
||||||
label='New Item'
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Filter'
|
|
||||||
onClick={addFilter}
|
|
||||||
/>
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Download CSV'
|
|
||||||
onClick={getCartCSV}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Upload CSV'
|
|
||||||
onClick={() => setIsModalActive(true)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className='md:inline-flex items-center ms-auto'>
|
|
||||||
<div id='delete-rows-button'></div>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
<CardBox className='mb-6' hasTable>
|
|
||||||
<TableCart
|
|
||||||
filterItems={filterItems}
|
|
||||||
setFilterItems={setFilterItems}
|
|
||||||
filters={filters}
|
|
||||||
showGrid={true}
|
|
||||||
/>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
<CardBoxModal
|
|
||||||
title='Upload CSV'
|
|
||||||
buttonColor='info'
|
|
||||||
buttonLabel={'Confirm'}
|
|
||||||
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
|
||||||
isActive={isModalActive}
|
|
||||||
onConfirm={onModalConfirm}
|
|
||||||
onCancel={onModalCancel}
|
|
||||||
>
|
|
||||||
<DragDropFilePicker
|
|
||||||
file={csvFile}
|
|
||||||
setFile={setCsvFile}
|
|
||||||
formats={'.csv'}
|
|
||||||
/>
|
|
||||||
</CardBoxModal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
CartTablesPage.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'READ_CART'}>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CartTablesPage;
|
|
||||||
@ -1,92 +0,0 @@
|
|||||||
import React, { ReactElement, useEffect } from 'react';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import DatePicker from 'react-datepicker';
|
|
||||||
import 'react-datepicker/dist/react-datepicker.css';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { fetch } from '../../stores/cart/cartSlice';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import ImageField from '../../components/ImageField';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const CartView = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const { cart } = useAppSelector((state) => state.cart);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const { id } = router.query;
|
|
||||||
|
|
||||||
function removeLastCharacter(str) {
|
|
||||||
console.log(str, `str`);
|
|
||||||
return str.slice(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetch({ id }));
|
|
||||||
}, [dispatch, id]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('View cart')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title={removeLastCharacter('View cart')}
|
|
||||||
main
|
|
||||||
>
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Edit'
|
|
||||||
href={`/cart/cart-edit/?id=${id}`}
|
|
||||||
/>
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>agencies</p>
|
|
||||||
|
|
||||||
<p>{cart?.agencies?.name ?? 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>User</p>
|
|
||||||
|
|
||||||
<p>{cart?.user?.firstName ?? 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Back'
|
|
||||||
onClick={() => router.push('/cart/cart-list')}
|
|
||||||
/>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
CartView.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'READ_CART'}>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CartView;
|
|
||||||
@ -35,7 +35,6 @@ const Dashboard = () => {
|
|||||||
const [roles, setRoles] = React.useState(loadingMessage);
|
const [roles, setRoles] = React.useState(loadingMessage);
|
||||||
const [permissions, setPermissions] = React.useState(loadingMessage);
|
const [permissions, setPermissions] = React.useState(loadingMessage);
|
||||||
const [agencies, setAgencies] = React.useState(loadingMessage);
|
const [agencies, setAgencies] = React.useState(loadingMessage);
|
||||||
const [cart, setCart] = React.useState(loadingMessage);
|
|
||||||
|
|
||||||
const [widgetsRole, setWidgetsRole] = React.useState({
|
const [widgetsRole, setWidgetsRole] = React.useState({
|
||||||
role: { value: '', label: '' },
|
role: { value: '', label: '' },
|
||||||
@ -56,7 +55,6 @@ const Dashboard = () => {
|
|||||||
'roles',
|
'roles',
|
||||||
'permissions',
|
'permissions',
|
||||||
'agencies',
|
'agencies',
|
||||||
'cart',
|
|
||||||
];
|
];
|
||||||
const fns = [
|
const fns = [
|
||||||
setUsers,
|
setUsers,
|
||||||
@ -66,7 +64,6 @@ const Dashboard = () => {
|
|||||||
setRoles,
|
setRoles,
|
||||||
setPermissions,
|
setPermissions,
|
||||||
setAgencies,
|
setAgencies,
|
||||||
setCart,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const requests = entities.map((entity, index) => {
|
const requests = entities.map((entity, index) => {
|
||||||
@ -418,38 +415,6 @@ const Dashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{hasPermission(currentUser, 'READ_CART') && (
|
|
||||||
<Link href={'/cart/cart-list'}>
|
|
||||||
<div
|
|
||||||
className={`${
|
|
||||||
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
|
||||||
} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
|
||||||
>
|
|
||||||
<div className='flex justify-between align-center'>
|
|
||||||
<div>
|
|
||||||
<div className='text-lg leading-tight text-gray-500 dark:text-gray-400'>
|
|
||||||
Cart
|
|
||||||
</div>
|
|
||||||
<div className='text-3xl leading-tight font-semibold'>
|
|
||||||
{cart}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<BaseIcon
|
|
||||||
className={`${iconsColor}`}
|
|
||||||
w='w-16'
|
|
||||||
h='h-16'
|
|
||||||
size={48}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
path={icon.mdiTable || icon.mdiTable}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</SectionMain>
|
</SectionMain>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -171,7 +171,7 @@ export default function WebSite() {
|
|||||||
<FeaturesSection
|
<FeaturesSection
|
||||||
projectName={'FlyAru-Powered by Arwa Travel Group'}
|
projectName={'FlyAru-Powered by Arwa Travel Group'}
|
||||||
image={['Iconic travel destinations collage']}
|
image={['Iconic travel destinations collage']}
|
||||||
withBg={0}
|
withBg={1}
|
||||||
features={features_points}
|
features={features_points}
|
||||||
mainText={`Explore ${projectName} Features`}
|
mainText={`Explore ${projectName} Features`}
|
||||||
subTitle={`Discover the unique features of ${projectName} that make your travel planning seamless and enjoyable.`}
|
subTitle={`Discover the unique features of ${projectName} that make your travel planning seamless and enjoyable.`}
|
||||||
|
|||||||
@ -51,8 +51,6 @@ const EditTours = () => {
|
|||||||
agency: null,
|
agency: null,
|
||||||
|
|
||||||
agencies: null,
|
agencies: null,
|
||||||
|
|
||||||
image_url: '',
|
|
||||||
};
|
};
|
||||||
const [initialValues, setInitialValues] = useState(initVals);
|
const [initialValues, setInitialValues] = useState(initVals);
|
||||||
|
|
||||||
@ -183,10 +181,6 @@ const EditTours = () => {
|
|||||||
></Field>
|
></Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<FormField label='Image url'>
|
|
||||||
<Field name='image_url' placeholder='Image url' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
<BaseButtons>
|
<BaseButtons>
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
<BaseButton type='submit' color='info' label='Submit' />
|
||||||
|
|||||||
@ -51,8 +51,6 @@ const EditToursPage = () => {
|
|||||||
agency: null,
|
agency: null,
|
||||||
|
|
||||||
agencies: null,
|
agencies: null,
|
||||||
|
|
||||||
image_url: '',
|
|
||||||
};
|
};
|
||||||
const [initialValues, setInitialValues] = useState(initVals);
|
const [initialValues, setInitialValues] = useState(initVals);
|
||||||
|
|
||||||
@ -181,10 +179,6 @@ const EditToursPage = () => {
|
|||||||
></Field>
|
></Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<FormField label='Image url'>
|
|
||||||
<Field name='image_url' placeholder='Image url' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
<BaseButtons>
|
<BaseButtons>
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
<BaseButton type='submit' color='info' label='Submit' />
|
||||||
|
|||||||
@ -31,7 +31,6 @@ const ToursTablesPage = () => {
|
|||||||
const [filters] = useState([
|
const [filters] = useState([
|
||||||
{ label: 'TourTitle', title: 'title' },
|
{ label: 'TourTitle', title: 'title' },
|
||||||
{ label: 'Description', title: 'description' },
|
{ label: 'Description', title: 'description' },
|
||||||
{ label: 'Image url', title: 'image_url' },
|
|
||||||
|
|
||||||
{ label: 'Price', title: 'price', number: 'true' },
|
{ label: 'Price', title: 'price', number: 'true' },
|
||||||
{ label: 'StartDate', title: 'start_date', date: 'true' },
|
{ label: 'StartDate', title: 'start_date', date: 'true' },
|
||||||
|
|||||||
@ -46,8 +46,6 @@ const initialValues = {
|
|||||||
agency: '',
|
agency: '',
|
||||||
|
|
||||||
agencies: '',
|
agencies: '',
|
||||||
|
|
||||||
image_url: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ToursNew = () => {
|
const ToursNew = () => {
|
||||||
@ -141,10 +139,6 @@ const ToursNew = () => {
|
|||||||
></Field>
|
></Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<FormField label='Image url'>
|
|
||||||
<Field name='image_url' placeholder='Image url' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
<BaseButtons>
|
<BaseButtons>
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
<BaseButton type='submit' color='info' label='Submit' />
|
||||||
|
|||||||
@ -31,7 +31,6 @@ const ToursTablesPage = () => {
|
|||||||
const [filters] = useState([
|
const [filters] = useState([
|
||||||
{ label: 'TourTitle', title: 'title' },
|
{ label: 'TourTitle', title: 'title' },
|
||||||
{ label: 'Description', title: 'description' },
|
{ label: 'Description', title: 'description' },
|
||||||
{ label: 'Image url', title: 'image_url' },
|
|
||||||
|
|
||||||
{ label: 'Price', title: 'price', number: 'true' },
|
{ label: 'Price', title: 'price', number: 'true' },
|
||||||
{ label: 'StartDate', title: 'start_date', date: 'true' },
|
{ label: 'StartDate', title: 'start_date', date: 'true' },
|
||||||
|
|||||||
@ -125,11 +125,6 @@ const ToursView = () => {
|
|||||||
<p>{tours?.agencies?.name ?? 'No data'}</p>
|
<p>{tours?.agencies?.name ?? 'No data'}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Image url</p>
|
|
||||||
<p>{tours?.image_url}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<p className={'block font-bold mb-2'}>Bookings Tour</p>
|
<p className={'block font-bold mb-2'}>Bookings Tour</p>
|
||||||
<CardBox
|
<CardBox
|
||||||
@ -173,47 +168,6 @@ const ToursView = () => {
|
|||||||
</CardBox>
|
</CardBox>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
<>
|
|
||||||
<p className={'block font-bold mb-2'}>Cartitem Tour</p>
|
|
||||||
<CardBox
|
|
||||||
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
|
||||||
hasTable
|
|
||||||
>
|
|
||||||
<div className='overflow-x-auto'>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Quantity</th>
|
|
||||||
|
|
||||||
<th>Unitprice</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{tours.cartitem_tour &&
|
|
||||||
Array.isArray(tours.cartitem_tour) &&
|
|
||||||
tours.cartitem_tour.map((item: any) => (
|
|
||||||
<tr
|
|
||||||
key={item.id}
|
|
||||||
onClick={() =>
|
|
||||||
router.push(
|
|
||||||
`/cartitem/cartitem-view/?id=${item.id}`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<td data-label='quantity'>{item.quantity}</td>
|
|
||||||
|
|
||||||
<td data-label='unitprice'>{item.unitprice}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{!tours?.cartitem_tour?.length && (
|
|
||||||
<div className={'text-center py-4'}>No data</div>
|
|
||||||
)}
|
|
||||||
</CardBox>
|
|
||||||
</>
|
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
|
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
|||||||
@ -191,37 +191,6 @@ const UsersView = () => {
|
|||||||
</CardBox>
|
</CardBox>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
<>
|
|
||||||
<p className={'block font-bold mb-2'}>Cart User</p>
|
|
||||||
<CardBox
|
|
||||||
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
|
||||||
hasTable
|
|
||||||
>
|
|
||||||
<div className='overflow-x-auto'>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr></tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{users.cart_user &&
|
|
||||||
Array.isArray(users.cart_user) &&
|
|
||||||
users.cart_user.map((item: any) => (
|
|
||||||
<tr
|
|
||||||
key={item.id}
|
|
||||||
onClick={() =>
|
|
||||||
router.push(`/cart/cart-view/?id=${item.id}`)
|
|
||||||
}
|
|
||||||
></tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{!users?.cart_user?.length && (
|
|
||||||
<div className={'text-center py-4'}>No data</div>
|
|
||||||
)}
|
|
||||||
</CardBox>
|
|
||||||
</>
|
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
|
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
|||||||
@ -1,236 +0,0 @@
|
|||||||
import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit';
|
|
||||||
import axios from 'axios';
|
|
||||||
import {
|
|
||||||
fulfilledNotify,
|
|
||||||
rejectNotify,
|
|
||||||
resetNotify,
|
|
||||||
} from '../../helpers/notifyStateHandler';
|
|
||||||
|
|
||||||
interface MainState {
|
|
||||||
cart: any;
|
|
||||||
loading: boolean;
|
|
||||||
count: number;
|
|
||||||
refetch: boolean;
|
|
||||||
rolesWidgets: any[];
|
|
||||||
notify: {
|
|
||||||
showNotification: boolean;
|
|
||||||
textNotification: string;
|
|
||||||
typeNotification: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: MainState = {
|
|
||||||
cart: [],
|
|
||||||
loading: false,
|
|
||||||
count: 0,
|
|
||||||
refetch: false,
|
|
||||||
rolesWidgets: [],
|
|
||||||
notify: {
|
|
||||||
showNotification: false,
|
|
||||||
textNotification: '',
|
|
||||||
typeNotification: 'warn',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const fetch = createAsyncThunk('cart/fetch', async (data: any) => {
|
|
||||||
const { id, query } = data;
|
|
||||||
const result = await axios.get(`cart${query || (id ? `/${id}` : '')}`);
|
|
||||||
return id
|
|
||||||
? result.data
|
|
||||||
: { rows: result.data.rows, count: result.data.count };
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteItemsByIds = createAsyncThunk(
|
|
||||||
'cart/deleteByIds',
|
|
||||||
async (data: any, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
await axios.post('cart/deleteByIds', { data });
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const deleteItem = createAsyncThunk(
|
|
||||||
'cart/deleteCart',
|
|
||||||
async (id: string, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
await axios.delete(`cart/${id}`);
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const create = createAsyncThunk(
|
|
||||||
'cart/createCart',
|
|
||||||
async (data: any, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const result = await axios.post('cart', { data });
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const uploadCsv = createAsyncThunk(
|
|
||||||
'cart/uploadCsv',
|
|
||||||
async (file: File, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const data = new FormData();
|
|
||||||
data.append('file', file);
|
|
||||||
data.append('filename', file.name);
|
|
||||||
|
|
||||||
const result = await axios.post('cart/bulk-import', data, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const update = createAsyncThunk(
|
|
||||||
'cart/updateCart',
|
|
||||||
async (payload: any, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const result = await axios.put(`cart/${payload.id}`, {
|
|
||||||
id: payload.id,
|
|
||||||
data: payload.data,
|
|
||||||
});
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const cartSlice = createSlice({
|
|
||||||
name: 'cart',
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
setRefetch: (state, action: PayloadAction<boolean>) => {
|
|
||||||
state.refetch = action.payload;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder.addCase(fetch.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(fetch.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(fetch.fulfilled, (state, action) => {
|
|
||||||
if (action.payload.rows && action.payload.count >= 0) {
|
|
||||||
state.cart = action.payload.rows;
|
|
||||||
state.count = action.payload.count;
|
|
||||||
} else {
|
|
||||||
state.cart = action.payload;
|
|
||||||
}
|
|
||||||
state.loading = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItemsByIds.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItemsByIds.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, 'Cart has been deleted');
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItemsByIds.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItem.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItem.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, `${'Cart'.slice(0, -1)} has been deleted`);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItem.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(create.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(create.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(create.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, `${'Cart'.slice(0, -1)} has been created`);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(update.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(update.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, `${'Cart'.slice(0, -1)} has been updated`);
|
|
||||||
});
|
|
||||||
builder.addCase(update.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(uploadCsv.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(uploadCsv.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, 'Cart has been uploaded');
|
|
||||||
});
|
|
||||||
builder.addCase(uploadCsv.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Action creators are generated for each case reducer function
|
|
||||||
export const { setRefetch } = cartSlice.actions;
|
|
||||||
|
|
||||||
export default cartSlice.reducer;
|
|
||||||
@ -11,7 +11,6 @@ import toursSlice from './tours/toursSlice';
|
|||||||
import rolesSlice from './roles/rolesSlice';
|
import rolesSlice from './roles/rolesSlice';
|
||||||
import permissionsSlice from './permissions/permissionsSlice';
|
import permissionsSlice from './permissions/permissionsSlice';
|
||||||
import agenciesSlice from './agencies/agenciesSlice';
|
import agenciesSlice from './agencies/agenciesSlice';
|
||||||
import cartSlice from './cart/cartSlice';
|
|
||||||
|
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
@ -27,7 +26,6 @@ export const store = configureStore({
|
|||||||
roles: rolesSlice,
|
roles: rolesSlice,
|
||||||
permissions: permissionsSlice,
|
permissions: permissionsSlice,
|
||||||
agencies: agenciesSlice,
|
agencies: agenciesSlice,
|
||||||
cart: cartSlice,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user