29737/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-09 14:08:45 +00:00

428 lines
9.6 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Administrators = db.administrators;
const Clients = db.clients;
const Resources = db.resources;
const Sessions = db.sessions;
const Supervisors = db.supervisors;
const Therapists = db.therapists;
const AdministratorsData = [
{
// type code here for "relation_one" field
role: 'Platform Manager',
},
{
// type code here for "relation_one" field
role: 'System Coordinator',
},
{
// type code here for "relation_one" field
role: 'Operations Lead',
},
];
const ClientsData = [
{
// type code here for "relation_one" field
mood: 'Happy',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
mood: 'Anxious',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
mood: 'Calm',
// type code here for "relation_many" field
},
];
const ResourcesData = [
{
title: 'Guided Meditation for Relaxation',
content: 'A guided meditation session to help you relax and unwind.',
type: 'meditation',
},
{
title: 'Understanding Anxiety',
content: 'An article explaining the causes and symptoms of anxiety.',
type: 'meditation',
},
{
title: 'Mindfulness Techniques',
content: 'A video tutorial on practicing mindfulness.',
type: 'article',
},
];
const SessionsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-01T10:00:00Z'),
end_time: new Date('2023-10-01T11:00:00Z'),
notes: 'Discussed progress and set new goals.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-08T10:00:00Z'),
end_time: new Date('2023-10-08T11:00:00Z'),
notes: 'Reviewed coping strategies.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-02T14:00:00Z'),
end_time: new Date('2023-10-02T15:00:00Z'),
notes: 'Explored family dynamics.',
},
];
const SupervisorsData = [
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
const TherapistsData = [
{
// type code here for "relation_one" field
specialization: 'Cognitive Behavioral Therapy',
},
{
// type code here for "relation_one" field
specialization: 'Family Therapy',
},
{
// type code here for "relation_one" field
specialization: 'Art Therapy',
},
];
// Similar logic for "relation_many"
async function associateAdministratorWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Administrator0 = await Administrators.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Administrator0?.setUser) {
await Administrator0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Administrator1 = await Administrators.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Administrator1?.setUser) {
await Administrator1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Administrator2 = await Administrators.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Administrator2?.setUser) {
await Administrator2.setUser(relatedUser2);
}
}
async function associateClientWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Client0 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Client0?.setUser) {
await Client0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Client1 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Client1?.setUser) {
await Client1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Client2 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Client2?.setUser) {
await Client2.setUser(relatedUser2);
}
}
// Similar logic for "relation_many"
async function associateSessionWithTherapist() {
const relatedTherapist0 = await Therapists.findOne({
offset: Math.floor(Math.random() * (await Therapists.count())),
});
const Session0 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Session0?.setTherapist) {
await Session0.setTherapist(relatedTherapist0);
}
const relatedTherapist1 = await Therapists.findOne({
offset: Math.floor(Math.random() * (await Therapists.count())),
});
const Session1 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Session1?.setTherapist) {
await Session1.setTherapist(relatedTherapist1);
}
const relatedTherapist2 = await Therapists.findOne({
offset: Math.floor(Math.random() * (await Therapists.count())),
});
const Session2 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Session2?.setTherapist) {
await Session2.setTherapist(relatedTherapist2);
}
}
async function associateSessionWithClient() {
const relatedClient0 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Session0 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Session0?.setClient) {
await Session0.setClient(relatedClient0);
}
const relatedClient1 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Session1 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Session1?.setClient) {
await Session1.setClient(relatedClient1);
}
const relatedClient2 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Session2 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Session2?.setClient) {
await Session2.setClient(relatedClient2);
}
}
async function associateSupervisorWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Supervisor0 = await Supervisors.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Supervisor0?.setUser) {
await Supervisor0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Supervisor1 = await Supervisors.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Supervisor1?.setUser) {
await Supervisor1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Supervisor2 = await Supervisors.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Supervisor2?.setUser) {
await Supervisor2.setUser(relatedUser2);
}
}
// Similar logic for "relation_many"
async function associateTherapistWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Therapist0 = await Therapists.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Therapist0?.setUser) {
await Therapist0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Therapist1 = await Therapists.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Therapist1?.setUser) {
await Therapist1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Therapist2 = await Therapists.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Therapist2?.setUser) {
await Therapist2.setUser(relatedUser2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Administrators.bulkCreate(AdministratorsData);
await Clients.bulkCreate(ClientsData);
await Resources.bulkCreate(ResourcesData);
await Sessions.bulkCreate(SessionsData);
await Supervisors.bulkCreate(SupervisorsData);
await Therapists.bulkCreate(TherapistsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAdministratorWithUser(),
await associateClientWithUser(),
// Similar logic for "relation_many"
await associateSessionWithTherapist(),
await associateSessionWithClient(),
await associateSupervisorWithUser(),
// Similar logic for "relation_many"
await associateTherapistWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('administrators', null, {});
await queryInterface.bulkDelete('clients', null, {});
await queryInterface.bulkDelete('resources', null, {});
await queryInterface.bulkDelete('sessions', null, {});
await queryInterface.bulkDelete('supervisors', null, {});
await queryInterface.bulkDelete('therapists', null, {});
},
};