375 lines
7.0 KiB
JavaScript
375 lines
7.0 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Badges = db.badges;
|
|
|
|
const DailyChallenges = db.daily_challenges;
|
|
|
|
const GameSessions = db.game_sessions;
|
|
|
|
const LeaderboardEntries = db.leaderboard_entries;
|
|
|
|
const Questions = db.questions;
|
|
|
|
const Rewards = db.rewards;
|
|
|
|
const BadgesData = [
|
|
{
|
|
name: 'Math Master',
|
|
|
|
description: 'Awarded for mastering all levels',
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Quick Solver',
|
|
|
|
description: 'Awarded for solving problems quickly',
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Streak Star',
|
|
|
|
description: 'Awarded for maintaining a streak',
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Challenge Champ',
|
|
|
|
description: 'Awarded for completing daily challenges',
|
|
|
|
// type code here for "images" field
|
|
},
|
|
];
|
|
|
|
const DailyChallengesData = [
|
|
{
|
|
date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
challenge_description: 'Solve 10 addition problems',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
challenge_description: 'Complete a geometry quiz',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
challenge_description: 'Achieve a streak of 5',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
challenge_description: 'Solve 5 word problems',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const GameSessionsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
level: 5,
|
|
|
|
score: 1500,
|
|
|
|
streak: 3,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
level: 3,
|
|
|
|
score: 900,
|
|
|
|
streak: 1,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
level: 2,
|
|
|
|
score: 600,
|
|
|
|
streak: 2,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
level: 4,
|
|
|
|
score: 1200,
|
|
|
|
streak: 4,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const LeaderboardEntriesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 1,
|
|
|
|
score: 1500,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 2,
|
|
|
|
score: 1200,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 3,
|
|
|
|
score: 900,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 4,
|
|
|
|
score: 600,
|
|
},
|
|
];
|
|
|
|
const QuestionsData = [
|
|
{
|
|
question_text: 'What is 5 + 3?',
|
|
|
|
difficulty: 'easy',
|
|
|
|
type: 'division',
|
|
},
|
|
|
|
{
|
|
question_text: 'What is 12 - 4?',
|
|
|
|
difficulty: 'hard',
|
|
|
|
type: 'mixed',
|
|
},
|
|
|
|
{
|
|
question_text: 'What is 6 x 7?',
|
|
|
|
difficulty: 'hard',
|
|
|
|
type: 'multiplication',
|
|
},
|
|
|
|
{
|
|
question_text: 'What is 56 ÷ 8?',
|
|
|
|
difficulty: 'hard',
|
|
|
|
type: 'geometry',
|
|
},
|
|
];
|
|
|
|
const RewardsData = [
|
|
{
|
|
name: 'Star Badge',
|
|
|
|
description: 'Earned for collecting 100 stars',
|
|
|
|
stars: 100,
|
|
},
|
|
|
|
{
|
|
name: 'Golden Trophy',
|
|
|
|
description: 'Earned for top leaderboard position',
|
|
|
|
stars: 200,
|
|
},
|
|
|
|
{
|
|
name: 'Silver Medal',
|
|
|
|
description: 'Earned for second place',
|
|
|
|
stars: 150,
|
|
},
|
|
|
|
{
|
|
name: 'Bronze Medal',
|
|
|
|
description: 'Earned for third place',
|
|
|
|
stars: 100,
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateGameSessionWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const GameSession0 = await GameSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (GameSession0?.setUser) {
|
|
await GameSession0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const GameSession1 = await GameSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (GameSession1?.setUser) {
|
|
await GameSession1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const GameSession2 = await GameSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (GameSession2?.setUser) {
|
|
await GameSession2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const GameSession3 = await GameSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (GameSession3?.setUser) {
|
|
await GameSession3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateLeaderboardEntryWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LeaderboardEntry0 = await LeaderboardEntries.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (LeaderboardEntry0?.setUser) {
|
|
await LeaderboardEntry0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LeaderboardEntry1 = await LeaderboardEntries.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (LeaderboardEntry1?.setUser) {
|
|
await LeaderboardEntry1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LeaderboardEntry2 = await LeaderboardEntries.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (LeaderboardEntry2?.setUser) {
|
|
await LeaderboardEntry2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LeaderboardEntry3 = await LeaderboardEntries.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (LeaderboardEntry3?.setUser) {
|
|
await LeaderboardEntry3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Badges.bulkCreate(BadgesData);
|
|
|
|
await DailyChallenges.bulkCreate(DailyChallengesData);
|
|
|
|
await GameSessions.bulkCreate(GameSessionsData);
|
|
|
|
await LeaderboardEntries.bulkCreate(LeaderboardEntriesData);
|
|
|
|
await Questions.bulkCreate(QuestionsData);
|
|
|
|
await Rewards.bulkCreate(RewardsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateGameSessionWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateLeaderboardEntryWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('badges', null, {});
|
|
|
|
await queryInterface.bulkDelete('daily_challenges', null, {});
|
|
|
|
await queryInterface.bulkDelete('game_sessions', null, {});
|
|
|
|
await queryInterface.bulkDelete('leaderboard_entries', null, {});
|
|
|
|
await queryInterface.bulkDelete('questions', null, {});
|
|
|
|
await queryInterface.bulkDelete('rewards', null, {});
|
|
},
|
|
};
|