diff --git a/backend/seeders/05-bullpens.js b/backend/seeders/05-bullpens.js new file mode 100644 index 0000000..b6ebf91 --- /dev/null +++ b/backend/seeders/05-bullpens.js @@ -0,0 +1,83 @@ +const process = require('process'); +const {createPlayer, createUsers} = require("../helper/seeder.helper"); + +const createBullpen = async (queryInterface, demoPlayer) => { + const startDate = new Date(); + const endDate = new Date(new Date().setTime(startDate.getTime() + 10 * 60000)); + const bullpens = [...Array(20).keys()].map(key => { + return { + pitcherId: demoPlayer.user.id, + startedAt: new Date(new Date().setDate(startDate.getDate()-5)), + finishedAt: new Date(new Date().setDate(startDate.getDate()-5)), + createdAt: new Date(), + updatedAt: new Date() + } + }) + await queryInterface.bulkInsert('BullpenSessions', bullpens); + + const pitchTypeIds = await queryInterface + .select(null, 'PitchTypes') + .map(pitchType => pitchType.id); + + // red: 21-28 + // orange: 11-18: + // green: 1-9 + const bullpenChart = [ + [21,22,23,24,25,26,27,28], + [11,12,13,14,15,16,17,18], + [1,2,3,4,5,6,7,8,9] + ] + + const dbBullpens = await queryInterface.select(null, 'BullpenSessions', { + where: { + pitcherId: demoPlayer.user.id + } + }); + + [...Array(20).keys()].map(key => { + return { + pitchTypeId: pitchTypeIds[Math.floor(Math.random() * pitchTypeIds.length)], + pitchTime: new Date(2025, 3, 22, 16, 7, 21), + aimedArea: 11, + hitArea: 12 + } + + }); +} + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up (queryInterface, /*Sequelize*/) { + if (process.env.NODE_ENV !== 'development') return; + + const roles = await queryInterface.select(null, 'Roles'); + const players = [{ + email: 'demo@bullpen.com', + password: 'demo$123', + firstName: 'Demo', + lastName: 'Player', + dateOfBirth: new Date(1975, 6, 19), + jerseyNumber: 33, + height: 187, + weight: 85, + gender: 'male', + bats: 'right', + throws: 'right', + state: 'active' + }]; + + const dbPlayers = await createPlayer(queryInterface, roles, players); + const demoPlayer = dbPlayers + .filter(player => player.user.auth.email === 'demo@bullpen.com').shift(); + + for (let i = 0; i < 10; ++i) { + createBullpen(queryInterface, demoPlayer); + } + }, + + async down (queryInterface, /*Sequelize*/) { + if (process.env.NODE_ENV !== 'development') return; + + return; + } +};