Compare commits

..

No commits in common. "ai-dev" and "master" have entirely different histories.

20 changed files with 134 additions and 145 deletions

5
.gitignore vendored
View File

@ -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

View File

@ -27,7 +27,7 @@ module.exports = class PrenotazioniDBApi {
transaction, transaction,
}); });
await prenotazioni.setGioco(data.gioco || null, { await prenotazioni.setTavolo(data.tavolo || null, {
transaction, transaction,
}); });
@ -86,9 +86,9 @@ module.exports = class PrenotazioniDBApi {
); );
} }
if (data.gioco !== undefined) { if (data.tavolo !== undefined) {
await prenotazioni.setGioco( await prenotazioni.setTavolo(
data.gioco, data.tavolo,
{ transaction }, { transaction },
); );
@ -162,7 +162,7 @@ module.exports = class PrenotazioniDBApi {
transaction, transaction,
}); });
output.gioco = await prenotazioni.getGioco({ output.tavolo = await prenotazioni.getTavolo({
transaction, transaction,
}); });
@ -210,21 +210,21 @@ module.exports = class PrenotazioniDBApi {
{ {
model: db.tavoli, model: db.tavoli,
as: 'gioco', as: 'tavolo',
where: filter.gioco where: filter.tavolo
? { ? {
[Op.or]: [ [Op.or]: [
{ {
id: { id: {
[Op.in]: filter.gioco [Op.in]: filter.tavolo
.split('|') .split('|')
.map((term) => Utils.uuid(term)), .map((term) => Utils.uuid(term)),
}, },
}, },
{ {
posti_totali: { posti_totali: {
[Op.or]: filter.gioco [Op.or]: filter.tavolo
.split('|') .split('|')
.map((term) => ({ [Op.iLike]: `%${term}%` })), .map((term) => ({ [Op.iLike]: `%${term}%` })),
}, },

View File

@ -154,7 +154,7 @@ module.exports = class TavoliDBApi {
const output = tavoli.get({ plain: true }); const output = tavoli.get({ plain: true });
output.prenotazioni_gioco = await tavoli.getPrenotazioni_gioco({ output.prenotazioni_tavolo = await tavoli.getPrenotazioni_tavolo({
transaction, transaction,
}); });

View File

@ -1,44 +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.renameColumn('prenotazioni', 'tavoloId', 'giocoId', {
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.renameColumn('prenotazioni', 'giocoId', 'tavoloId', {
transaction,
});
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
};

View File

@ -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;
}
},
};

View File

@ -45,9 +45,9 @@ module.exports = function (sequelize, DataTypes) {
}); });
db.prenotazioni.belongsTo(db.tavoli, { db.prenotazioni.belongsTo(db.tavoli, {
as: 'gioco', as: 'tavolo',
foreignKey: { foreignKey: {
name: 'giocoId', name: 'tavoloId',
}, },
constraints: false, constraints: false,
}); });

View File

@ -39,9 +39,9 @@ module.exports = function (sequelize, DataTypes) {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.tavoli.hasMany(db.prenotazioni, { db.tavoli.hasMany(db.prenotazioni, {
as: 'prenotazioni_gioco', as: 'prenotazioni_tavolo',
foreignKey: { foreignKey: {
name: 'giocoId', name: 'tavoloId',
}, },
constraints: false, constraints: false,
}); });

View File

@ -27,6 +27,12 @@ const GiochiData = [
// type code here for "images" field // type code here for "images" field
}, },
{
nome: 'Ticket to Ride',
// type code here for "images" field
},
]; ];
const PrenotazioniData = [ const PrenotazioniData = [
@ -53,6 +59,14 @@ const PrenotazioniData = [
data_prenotazione: new Date('2023-11-12T12:00:00Z'), data_prenotazione: new Date('2023-11-12T12:00:00Z'),
}, },
{
// type code here for "relation_one" field
// type code here for "relation_one" field
data_prenotazione: new Date('2023-11-13T13:00:00Z'),
},
]; ];
const SerateData = [ const SerateData = [
@ -79,6 +93,14 @@ const SerateData = [
numero_tavoli: 6, numero_tavoli: 6,
}, },
{
tema: 'Serata giochi da tavolo classici',
data: new Date('2023-12-06T19:00:00Z'),
numero_tavoli: 3,
},
]; ];
const TavoliData = [ const TavoliData = [
@ -111,6 +133,16 @@ const TavoliData = [
posti_occupati: 4, posti_occupati: 4,
}, },
{
// type code here for "relation_one" field
// type code here for "relation_one" field
posti_totali: 3,
posti_occupati: 1,
},
]; ];
// Similar logic for "relation_many" // Similar logic for "relation_many"
@ -148,40 +180,62 @@ async function associatePrenotazioniWithUtente() {
if (Prenotazioni2?.setUtente) { if (Prenotazioni2?.setUtente) {
await Prenotazioni2.setUtente(relatedUtente2); await Prenotazioni2.setUtente(relatedUtente2);
} }
const relatedUtente3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Prenotazioni3 = await Prenotazioni.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Prenotazioni3?.setUtente) {
await Prenotazioni3.setUtente(relatedUtente3);
}
} }
async function associatePrenotazioniWithGioco() { async function associatePrenotazioniWithTavolo() {
const relatedGioco0 = await Tavoli.findOne({ const relatedTavolo0 = await Tavoli.findOne({
offset: Math.floor(Math.random() * (await Tavoli.count())), offset: Math.floor(Math.random() * (await Tavoli.count())),
}); });
const Prenotazioni0 = await Prenotazioni.findOne({ const Prenotazioni0 = await Prenotazioni.findOne({
order: [['id', 'ASC']], order: [['id', 'ASC']],
offset: 0, offset: 0,
}); });
if (Prenotazioni0?.setGioco) { if (Prenotazioni0?.setTavolo) {
await Prenotazioni0.setGioco(relatedGioco0); await Prenotazioni0.setTavolo(relatedTavolo0);
} }
const relatedGioco1 = await Tavoli.findOne({ const relatedTavolo1 = await Tavoli.findOne({
offset: Math.floor(Math.random() * (await Tavoli.count())), offset: Math.floor(Math.random() * (await Tavoli.count())),
}); });
const Prenotazioni1 = await Prenotazioni.findOne({ const Prenotazioni1 = await Prenotazioni.findOne({
order: [['id', 'ASC']], order: [['id', 'ASC']],
offset: 1, offset: 1,
}); });
if (Prenotazioni1?.setGioco) { if (Prenotazioni1?.setTavolo) {
await Prenotazioni1.setGioco(relatedGioco1); await Prenotazioni1.setTavolo(relatedTavolo1);
} }
const relatedGioco2 = await Tavoli.findOne({ const relatedTavolo2 = await Tavoli.findOne({
offset: Math.floor(Math.random() * (await Tavoli.count())), offset: Math.floor(Math.random() * (await Tavoli.count())),
}); });
const Prenotazioni2 = await Prenotazioni.findOne({ const Prenotazioni2 = await Prenotazioni.findOne({
order: [['id', 'ASC']], order: [['id', 'ASC']],
offset: 2, offset: 2,
}); });
if (Prenotazioni2?.setGioco) { if (Prenotazioni2?.setTavolo) {
await Prenotazioni2.setGioco(relatedGioco2); await Prenotazioni2.setTavolo(relatedTavolo2);
}
const relatedTavolo3 = await Tavoli.findOne({
offset: Math.floor(Math.random() * (await Tavoli.count())),
});
const Prenotazioni3 = await Prenotazioni.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Prenotazioni3?.setTavolo) {
await Prenotazioni3.setTavolo(relatedTavolo3);
} }
} }
@ -218,6 +272,17 @@ async function associateTavoliWithSeratum() {
if (Tavoli2?.setSeratum) { if (Tavoli2?.setSeratum) {
await Tavoli2.setSeratum(relatedSeratum2); await Tavoli2.setSeratum(relatedSeratum2);
} }
const relatedSeratum3 = await Serate.findOne({
offset: Math.floor(Math.random() * (await Serate.count())),
});
const Tavoli3 = await Tavoli.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Tavoli3?.setSeratum) {
await Tavoli3.setSeratum(relatedSeratum3);
}
} }
async function associateTavoliWithGioco() { async function associateTavoliWithGioco() {
@ -253,6 +318,17 @@ async function associateTavoliWithGioco() {
if (Tavoli2?.setGioco) { if (Tavoli2?.setGioco) {
await Tavoli2.setGioco(relatedGioco2); await Tavoli2.setGioco(relatedGioco2);
} }
const relatedGioco3 = await Giochi.findOne({
offset: Math.floor(Math.random() * (await Giochi.count())),
});
const Tavoli3 = await Tavoli.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Tavoli3?.setGioco) {
await Tavoli3.setGioco(relatedGioco3);
}
} }
module.exports = { module.exports = {
@ -270,7 +346,7 @@ module.exports = {
await associatePrenotazioniWithUtente(), await associatePrenotazioniWithUtente(),
await associatePrenotazioniWithGioco(), await associatePrenotazioniWithTavolo(),
await associateTavoliWithSeratum(), await associateTavoliWithSeratum(),

View File

@ -1 +0,0 @@
{}

View File

@ -89,11 +89,11 @@ const CardPrenotazioni = ({
<div className='flex justify-between gap-x-4 py-3'> <div className='flex justify-between gap-x-4 py-3'>
<dt className=' text-gray-500 dark:text-dark-600'> <dt className=' text-gray-500 dark:text-dark-600'>
Giochi Tavolo
</dt> </dt>
<dd className='flex items-start gap-x-2'> <dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'> <div className='font-medium line-clamp-4'>
{dataFormatter.tavoliOneListFormatter(item.gioco)} {dataFormatter.tavoliOneListFormatter(item.tavolo)}
</div> </div>
</dd> </dd>
</div> </div>

View File

@ -61,9 +61,9 @@ const ListPrenotazioni = ({
</div> </div>
<div className={'flex-1 px-3'}> <div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500 '}>Giochi</p> <p className={'text-xs text-gray-500 '}>Tavolo</p>
<p className={'line-clamp-2'}> <p className={'line-clamp-2'}>
{dataFormatter.tavoliOneListFormatter(item.gioco)} {dataFormatter.tavoliOneListFormatter(item.tavolo)}
</p> </p>
</div> </div>

View File

@ -59,8 +59,8 @@ export const loadColumns = async (
}, },
{ {
field: 'gioco', field: 'tavolo',
headerName: 'Giochi', headerName: 'Tavolo',
flex: 1, flex: 1,
minWidth: 120, minWidth: 120,
filterable: false, filterable: false,

View File

@ -38,7 +38,7 @@ const EditPrenotazioni = () => {
const initVals = { const initVals = {
utente: null, utente: null,
gioco: null, tavolo: null,
data_prenotazione: new Date(), data_prenotazione: new Date(),
}; };
@ -106,12 +106,12 @@ const EditPrenotazioni = () => {
></Field> ></Field>
</FormField> </FormField>
<FormField label='Giochi' labelFor='gioco'> <FormField label='Tavolo' labelFor='tavolo'>
<Field <Field
name='gioco' name='tavolo'
id='gioco' id='tavolo'
component={SelectField} component={SelectField}
options={initialValues.gioco} options={initialValues.tavolo}
itemRef={'tavoli'} itemRef={'tavoli'}
showField={'posti_totali'} showField={'posti_totali'}
></Field> ></Field>

View File

@ -38,7 +38,7 @@ const EditPrenotazioniPage = () => {
const initVals = { const initVals = {
utente: null, utente: null,
gioco: null, tavolo: null,
data_prenotazione: new Date(), data_prenotazione: new Date(),
}; };
@ -104,12 +104,12 @@ const EditPrenotazioniPage = () => {
></Field> ></Field>
</FormField> </FormField>
<FormField label='Giochi' labelFor='gioco'> <FormField label='Tavolo' labelFor='tavolo'>
<Field <Field
name='gioco' name='tavolo'
id='gioco' id='tavolo'
component={SelectField} component={SelectField}
options={initialValues.gioco} options={initialValues.tavolo}
itemRef={'tavoli'} itemRef={'tavoli'}
showField={'posti_totali'} showField={'posti_totali'}
></Field> ></Field>

View File

@ -36,7 +36,7 @@ const PrenotazioniTablesPage = () => {
{ label: 'Utente', title: 'utente' }, { label: 'Utente', title: 'utente' },
{ label: 'Giochi', title: 'gioco' }, { label: 'Tavolo', title: 'tavolo' },
]); ]);
const hasCreatePermission = const hasCreatePermission =

View File

@ -35,7 +35,7 @@ import moment from 'moment';
const initialValues = { const initialValues = {
utente: '', utente: '',
gioco: '', tavolo: '',
data_prenotazione: '', data_prenotazione: '',
}; };
@ -77,10 +77,10 @@ const PrenotazioniNew = () => {
></Field> ></Field>
</FormField> </FormField>
<FormField label='Giochi' labelFor='gioco'> <FormField label='Tavolo' labelFor='tavolo'>
<Field <Field
name='gioco' name='tavolo'
id='gioco' id='tavolo'
component={SelectField} component={SelectField}
options={[]} options={[]}
itemRef={'tavoli'} itemRef={'tavoli'}

View File

@ -36,7 +36,7 @@ const PrenotazioniTablesPage = () => {
{ label: 'Utente', title: 'utente' }, { label: 'Utente', title: 'utente' },
{ label: 'Giochi', title: 'gioco' }, { label: 'Tavolo', title: 'tavolo' },
]); ]);
const hasCreatePermission = const hasCreatePermission =

View File

@ -61,9 +61,9 @@ const PrenotazioniView = () => {
</div> </div>
<div className={'mb-4'}> <div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Giochi</p> <p className={'block font-bold mb-2'}>Tavolo</p>
<p>{prenotazioni?.gioco?.posti_totali ?? 'No data'}</p> <p>{prenotazioni?.tavolo?.posti_totali ?? 'No data'}</p>
</div> </div>
<FormField label='DataPrenotazione'> <FormField label='DataPrenotazione'>

View File

@ -77,7 +77,7 @@ const TavoliView = () => {
</div> </div>
<> <>
<p className={'block font-bold mb-2'}>Prenotazioni Giochi</p> <p className={'block font-bold mb-2'}>Prenotazioni Tavolo</p>
<CardBox <CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden' className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable hasTable
@ -90,9 +90,9 @@ const TavoliView = () => {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{tavoli.prenotazioni_gioco && {tavoli.prenotazioni_tavolo &&
Array.isArray(tavoli.prenotazioni_gioco) && Array.isArray(tavoli.prenotazioni_tavolo) &&
tavoli.prenotazioni_gioco.map((item: any) => ( tavoli.prenotazioni_tavolo.map((item: any) => (
<tr <tr
key={item.id} key={item.id}
onClick={() => onClick={() =>
@ -111,7 +111,7 @@ const TavoliView = () => {
</tbody> </tbody>
</table> </table>
</div> </div>
{!tavoli?.prenotazioni_gioco?.length && ( {!tavoli?.prenotazioni_tavolo?.length && (
<div className={'text-center py-4'}>No data</div> <div className={'text-center py-4'}>No data</div>
)} )}
</CardBox> </CardBox>