30677/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-12 16:47:58 +00:00

147 lines
3.0 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Gestures = db.gestures;
const Videos = db.videos;
const GesturesData = [
{
name: 'Wave',
description: 'A simple hand wave to initiate actions.',
// type code here for "relation_many" field
},
{
name: 'Thumbs Up',
description: 'Gesture for approval or agreement.',
// type code here for "relation_many" field
},
{
name: 'Swipe Left',
description: 'Gesture to navigate left.',
// type code here for "relation_many" field
},
{
name: 'Swipe Right',
description: 'Gesture to navigate right.',
// type code here for "relation_many" field
},
];
const VideosData = [
{
title: 'Gesture Tutorial 1',
recorded_at: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Gesture Tutorial 2',
recorded_at: new Date('2023-10-02T11:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Gesture Tutorial 3',
recorded_at: new Date('2023-10-03T12:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Gesture Tutorial 4',
recorded_at: new Date('2023-10-04T13:00:00Z'),
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateVideoWithGesture() {
const relatedGesture0 = await Gestures.findOne({
offset: Math.floor(Math.random() * (await Gestures.count())),
});
const Video0 = await Videos.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Video0?.setGesture) {
await Video0.setGesture(relatedGesture0);
}
const relatedGesture1 = await Gestures.findOne({
offset: Math.floor(Math.random() * (await Gestures.count())),
});
const Video1 = await Videos.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Video1?.setGesture) {
await Video1.setGesture(relatedGesture1);
}
const relatedGesture2 = await Gestures.findOne({
offset: Math.floor(Math.random() * (await Gestures.count())),
});
const Video2 = await Videos.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Video2?.setGesture) {
await Video2.setGesture(relatedGesture2);
}
const relatedGesture3 = await Gestures.findOne({
offset: Math.floor(Math.random() * (await Gestures.count())),
});
const Video3 = await Videos.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Video3?.setGesture) {
await Video3.setGesture(relatedGesture3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Gestures.bulkCreate(GesturesData);
await Videos.bulkCreate(VideosData);
await Promise.all([
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateVideoWithGesture(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('gestures', null, {});
await queryInterface.bulkDelete('videos', null, {});
},
};