Skip to content

Commit

Permalink
Merge pull request #729 from elmadev/feature/cups-start-end
Browse files Browse the repository at this point in the history
feat(cups): add start and end time to /cups response
  • Loading branch information
sunehs authored Jan 4, 2025
2 parents c72e2d0 + 9c7cf17 commit c170bf4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/api/cups.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ const router = express.Router();
const getCups = async (ongoing = false) => {
const query = {
where: { Hidden: 0 },
attributes: {
include: [
[
sequelize.literal(
'(SELECT MIN(StartTime) FROM sitecup WHERE sitecup.CupGroupIndex = sitecupgroup.CupGroupIndex)',
),
'StartTime',
],
[
sequelize.literal(
'(SELECT MAX(EndTime) FROM sitecup WHERE sitecup.CupGroupIndex = sitecupgroup.CupGroupIndex)',
),
'EndTime',
],
],
},
};
if (ongoing) {
query.where.Finished = 0;
Expand Down Expand Up @@ -62,7 +78,11 @@ const getCups = async (ongoing = false) => {
];
}
const data = await SiteCupGroup.findAll(query);
return data;
return data.map(cup => ({
...cup.dataValues,
StartTime: moment(cup.dataValues.StartTime).format('X'),
EndTime: moment(cup.dataValues.EndTime).format('X'),
}));
};

const getCupById = async CupGroupIndex => {
Expand Down

0 comments on commit c170bf4

Please sign in to comment.