You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.6 KiB
TypeScript

import dotenv from "dotenv";
dotenv.config();
import { client } from "../db";
async function main() {
const users = await client.query(`
INSERT INTO users (first_name, last_name, email, password_hash, email_verified, is_admin) VALUES
('Filip', 'B P', 'fbp@gmail.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, true),
('User1', 'Lastname', 'u1@test.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, false),
('User2', 'Lastname', 'u2@test.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, false),
('User3', 'Lastname', 'u3@test.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, false),
('Trainer1', 'Lastname', 't1@test.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, false),
('Trainer2', 'Lastname', 't2@test.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, false),
('Admin1', 'Lastname', 'a1@test.com', '$2b$10$zxqwqZXo3DrLVTFx.hkQQ.uKeqhHMnok.G/4.Ivq1g647RaqYtgKC', true, true)
RETURNING id, email;
`);
const centers = await client.query(`
INSERT INTO centers (name, city, zip_code, address) VALUES
('Herning Fitness', 'Herning', '7400', 'Vej 123'),
('Aarhus Fitness', 'Aarhus', '8000', 'Alle 321')
RETURNING id, name;
`);
const trainers = await client.query(`
INSERT INTO trainers (user_id, center_id, hourly_price) VALUES
($1, $2, 10000),
($3, $4, 20000)
RETURNING id, user_id;
`, [
users.rows.find(user => user.email === "t1@test.com").id,
centers.rows[0].id,
users.rows.find(user => user.email === "t2@test.com").id,
centers.rows[1].id,
]);
const weekly_timeslots = await client.query(`
INSERT INTO weekly_timeslots (trainer_id, day_of_week, start_time, end_time) VALUES
($1, 1, '8:00:00', '9:00:00'),
($1, 1, '9:00:00', '10:00:00'),
($1, 1, '10:00:00', '11:00:00'),
($1, 1, '11:00:00', '12:00:00'),
($1, 1, '12:00:00', '13:00:00'),
($1, 1, '13:00:00', '14:00:00'),
($1, 1, '14:00:00', '15:00:00'),
($1, 2, '10:00:00', '13:00:00'),
($1, 3, '10:00:00', '15:00:00'),
($1, 3, '16:00:00', '17:00:00'),
($1, 4, '10:00:00', '11:30:00'),
($2, 1, '10:00:00', '11:00:00'),
($2, 1, '11:00:00', '12:00:00'),
($2, 1, '12:00:00', '13:00:00')
RETURNING id;
`, [
trainers.rows[0].id,
trainers.rows[1].id
]);
const reserved_timeslots = await client.query(`
INSERT INTO reserved_timeslots (trainer_id, start_time, end_time) VALUES
($1, '2023-04-24 11:00:00+2', '2023-04-24 12:00:00+2'),
($1, '2023-04-24 12:00:00+2', '2023-04-24 13:00:00+2'),
($1, '2023-04-01 11:00:00+2', '2023-04-01 12:00:00+2'),
($2, '2023-04-17 11:00:00+2', '2023-04-17 12:00:00+2'),
($2, '2023-04-10 12:00:00+2', '2023-04-10 13:00:00+2')
RETURNING id, trainer_id;
`, [
trainers.rows[0].id,
trainers.rows[1].id
]);
const orders = await client.query(`
INSERT INTO orders (timeslot_id, user_id, order_status, price, checkout_session) VALUES
($3, $1, 'CancelledByUser', 10000, ''),
($4, $1, 'CancelledByTrainer', 20000, ''),
($5, $2, 'Created', 20000, ''),
($6, $1, 'Confirmed', 20000, ''),
($7, $1, 'Failed', 20000, '')
RETURNING id;
`, [
users.rows.find(user => user.email === "u1@test.com").id,
users.rows.find(user => user.email === "u2@test.com").id,
reserved_timeslots.rows[0].id,
reserved_timeslots.rows[1].id,
reserved_timeslots.rows[2].id,
reserved_timeslots.rows[3].id,
reserved_timeslots.rows[4].id,
]);
client.end();
process.exit(0);
}
main();