Skip to content

Commit

Permalink
Merge branch 'dev' into fix/update-tournament-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TeddyRoncin authored Oct 17, 2023
2 parents 843684d + 225aacf commit 9a40d1b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
25 changes: 13 additions & 12 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ model CartItem {
}

model Item {
id String @id
name String
category ItemCategory
attribute String?
price Int
reducedPrice Int?
infos String? @db.VarChar(300)
image String?
stock Int?
availableFrom DateTime?
availableUntil DateTime?
cartItems CartItem[]
id String @id
name String
category ItemCategory
attribute String?
price Int
reducedPrice Int?
infos String? @db.VarChar(300)
image String?
stock Int?
availableFrom DateTime?
availableUntil DateTime?
position Int @default(0)
cartItems CartItem[]
@@map("items")
}
Expand Down
30 changes: 15 additions & 15 deletions seed.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
INSERT INTO `items` (`id`, `name`, `category`, `attribute`, `price`, `reducedPrice`, `infos`, `image`, `stock`) VALUES
('ticket-player', 'Place joueur', 'ticket', NULL, 2500, 2000, NULL, NULL, NULL),
('ticket-player-ssbu', 'Place joueur (SSBU)', 'ticket', NULL, 2200, 1700, NULL, NULL, NULL),
('ticket-coach', 'Place coach/manager', 'ticket', NULL, 1500, NULL, NULL, NULL, NULL),
('ticket-attendant', 'Place accompagnateur', 'ticket', NULL, 1500, NULL, NULL, NULL, NULL),
('ticket-spectator', 'Place spectateur', 'ticket', NULL, 1000, NULL, NULL, NULL, 100),
('discount-switch-ssbu', 'Réduction si tu amènes ta propre Nintendo Switch', 'supplement', NULL, -300, NULL, 'Une réduction applicable si tu amènes ta propre Nintendo Switch pendant le weekend. Il faut que tu aies le jeu SSBU avec tous les personnages et que tu prennes un cable HDMI.', NULL, 30),
('ethernet-7', 'Câble ethernet (7m)', 'supplement', NULL, 1000, NULL, 'Un câble ethernet est requis pour se brancher aux switchs des tables', NULL, NULL),
('multi-socket', 'Multiprise 3 trous', 'supplement', NULL, 500, NULL, 'Une multiprise 3 trous pour brancher tout ton setup', NULL, NULL),
('pin', "Pin's", 'supplement', NULL, 200, NULL, "Un pin's argenté, souvenir de cette LAN de folie", 'pin.png', 100),
('tshirt-s', 'T-shirt UA 2022 (Unixese)', 'supplement', 's', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30),
('tshirt-m', 'T-shirt UA 2022 (Unixese)', 'supplement', 'm', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30),
('tshirt-l', 'T-shirt UA 2022 (Unixese)', 'supplement', 'l', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30),
('tshirt-xl', 'T-shirt UA 2022 (Unixese)', 'supplement', 'xl', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30),
('pc', 'Location de PC', 'rent', NULL, 14000, NULL, 'Location de PC si tu ne peux pas amener le tien pendant l''UTT Arena. L''un des PC suivants sera mis à ta disposition :->AMD Ryzen 5 2600,16GB RAM SSD 500G° et 2060 ou 6600XT->INTEL I5 8500 16GB RAM SSD 500G° et 2060 ou 6600XT->AMD RYZEN 5 5600X 500G° SSD et 2060 ou 6600XT', NULL, 7);
INSERT INTO `items` (`id`, `name`, `category`, `attribute`, `price`, `reducedPrice`, `infos`, `image`, `stock`, `position`) VALUES
('ticket-player', 'Place joueur', 'ticket', NULL, 2500, 2000, NULL, NULL, NULL, 0),
('ticket-player-ssbu', 'Place joueur (SSBU)', 'ticket', NULL, 2200, 1700, NULL, NULL, NULL, 1),
('ticket-coach', 'Place coach/manager', 'ticket', NULL, 1500, NULL, NULL, NULL, NULL, 2),
('ticket-attendant', 'Place accompagnateur', 'ticket', NULL, 1500, NULL, NULL, NULL, NULL, 3),
('ticket-spectator', 'Place spectateur', 'ticket', NULL, 1000, NULL, NULL, NULL, 100, 4),
('discount-switch-ssbu', 'Réduction si tu amènes ta propre Nintendo Switch', 'supplement', NULL, -300, NULL, 'Une réduction applicable si tu amènes ta propre Nintendo Switch pendant le weekend. Il faut que tu aies le jeu SSBU avec tous les personnages et que tu prennes un cable HDMI.', NULL, 30, 5),
('ethernet-7', 'Câble ethernet (7m)', 'supplement', NULL, 1000, NULL, 'Un câble ethernet est requis pour se brancher aux switchs des tables', NULL, NULL, 11),
('multi-socket', 'Multiprise 3 trous', 'supplement', NULL, 500, NULL, 'Une multiprise 3 trous pour brancher tout ton setup', NULL, NULL, 12),
('pin', "Pin's", 'supplement', NULL, 200, NULL, "Un pin's argenté, souvenir de cette LAN de folie", 'pin.png', 100, 10),
('tshirt-s', 'T-shirt UA 2022 (Unixese)', 'supplement', 's', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30, 6),
('tshirt-m', 'T-shirt UA 2022 (Unixese)', 'supplement', 'm', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30, 7),
('tshirt-l', 'T-shirt UA 2022 (Unixese)', 'supplement', 'l', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30, 8),
('tshirt-xl', 'T-shirt UA 2022 (Unixese)', 'supplement', 'xl', 1500, NULL, 'Un t-shirt souvenir de cette LAN de folie', 'tshirt.png', 30, 9),
('pc', 'Location de PC', 'rent', NULL, 14000, NULL, 'Location de PC si tu ne peux pas amener le tien pendant l''UTT Arena. L''un des PC suivants sera mis à ta disposition :->AMD Ryzen 5 2600,16GB RAM SSD 500G° et 2060 ou 6600XT->INTEL I5 8500 16GB RAM SSD 500G° et 2060 ou 6600XT->AMD RYZEN 5 5600X 500G° SSD et 2060 ou 6600XT', NULL, 7, 13);

INSERT INTO `settings` (`id`, `value`) VALUES
('login', 0),
Expand Down
16 changes: 5 additions & 11 deletions src/operations/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { isPartnerSchool } from '../utils/helpers';

export const fetchAllItems = async (): Promise<Item[]> => {
// fetches the items
let items = await database.item.findMany();
const order = ['tshirt-s', 'tshirt-m', 'tshirt-l', 'tshirt-xl'];
// sort items according to size attribute
items = items.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
const items = await database.item.findMany({ orderBy: [{ position: 'asc' }] });

// Add a left property which tells how many items are there left
return Promise.all(
Expand Down Expand Up @@ -75,13 +72,10 @@ export const fetchUserItems = async (team?: Team, user?: User) => {
const currentTicket =
items.find((item) => item.id === `ticket-player-${team?.tournamentId}`) ??
items.find((item) => item.id === 'ticket-player');
items = [
...items.filter((item) => !item.id.startsWith('ticket-player')),
{
...currentTicket,
id: 'ticket-player',
},
];
// Remove every ticket-player* item except the currentTicket
items = items.filter((item) => !item.id.startsWith('ticket-player') || item.id === currentTicket.id);
// Update the currentTicket id
currentTicket.id = 'ticket-player';

return items;
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/email/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const generateTicketsEmail = (cart: DetailedCart) =>
},
{
title: 'Billet',
components: ["Tu reçevras ton *billet personnalisé* par mail quelques jours avant l'UTT Arena&nbsp;!"],
components: ["Tu recevras ton *billet personnalisé* par mail quelques jours avant l'UTT Arena&nbsp;!"],
},
{
title: 'Confirmation de commande',
Expand Down
12 changes: 9 additions & 3 deletions tests/items/getItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ describe('GET /items', () => {
});

it('should return items with their stock', async () => {
const items = await database.item.findMany();
// Fetch all items, order them by their position, and remove special ticket players and ssbu discount
const items = await database.item.findMany({
where: { NOT: { OR: [{ id: { startsWith: 'ticket-player-' } }, { id: 'discount-switch-ssbu' }] } },
orderBy: [{ position: 'asc' }],
});
const response = await request(app).get('/items').expect(200);

for (const responseItem of response.body)
expect(responseItem.left ?? null).to.be.equal(items.find((item) => item.name === responseItem.name).stock);
for (let index = 0; index < response.body.length; index++) {
expect(response.body[index].id).to.be.equal(items[index].id);
expect(response.body[index].left ?? null).to.be.equal(items[index].stock);
}
});
});

0 comments on commit 9a40d1b

Please sign in to comment.