Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rideam committed Aug 20, 2024
1 parent a66f141 commit 32ffd39
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 328 deletions.
83 changes: 42 additions & 41 deletions addExampleData.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import { readFileSync } from "fs";
import sequelize from "./config/database.js";
import { KendoUIAppointment, KendoUIResource } from "./models/index.js";

async function setupDatabase() {
// Wait for all models to synchronize with the database
await sequelize.sync();

// Now add example data
await addExampleData();
}

async function addExampleData() {
try {
// Read and parse the JSON data
const resourcesData = JSON.parse(
readFileSync("./initialData/kendouiResources.json")
);
const appointmentsData = JSON.parse(
readFileSync("./initialData/kendouiAppointments.json")
);

await sequelize.transaction(async (t) => {
const resources = await KendoUIResource.bulkCreate(resourcesData, {
transaction: t,
});
const appointments = await KendoUIAppointment.bulkCreate(
appointmentsData,
{ transaction: t }
);
return { resources, appointments };
});

console.log(
"resources and appointments added to database successfully."
);
} catch (error) {
console.error("Failed to add data to database due to an error: ", error);
}
}

import { readFileSync } from 'fs';
import sequelize from './config/database.js';
import { KendoUIAppointment, KendoUIResource } from './models/index.js';

async function setupDatabase() {
// Wait for all models to synchronize with the database
await sequelize.sync();

// Now add example data
await addExampleData();
}

async function addExampleData() {
try {
// Read and parse the JSON data
const resourcesData = JSON.parse(
readFileSync('./initialData/kendouiResources.json')
);
const appointmentsData = JSON.parse(
readFileSync('./initialData/kendouiAppointments.json')
);

await sequelize.transaction(async(t) => {
const resources = await KendoUIResource.bulkCreate(resourcesData, {
transaction : t
});
const appointments = await KendoUIAppointment.bulkCreate(
appointmentsData,
{ transaction : t }
);
return { resources, appointments };
});

console.log(
'resources and appointments added to database successfully.'
);
}
catch (error) {
console.error('Failed to add data to database due to an error: ', error);
}
}

setupDatabase();
14 changes: 7 additions & 7 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Sequelize } from "sequelize";

const sequelize = new Sequelize({
dialect: "sqlite",
storage: "./database.sqlite3",
});

import { Sequelize } from 'sequelize';

const sequelize = new Sequelize({
dialect : 'sqlite',
storage : './database.sqlite3'
});

export default sequelize;
132 changes: 66 additions & 66 deletions models/KendoUIAppointment.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { DataTypes } from "sequelize";
import sequelize from "../config/database.js";

const KendoUIAppointment = sequelize.define(
"KendoUIAppointment",
{
meetingID: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
start: {
type: DataTypes.DATE,
defaultValue: null,
},
end: {
type: DataTypes.DATE,
defaultValue: null,
},
startTimezone: {
type: DataTypes.STRING,
},
endTimezone: {
type: DataTypes.STRING,
},
description: {
type: DataTypes.STRING,
},
recurrenceID: {
type: DataTypes.STRING,
},
recurrenceRule: {
type: DataTypes.STRING,
},
recurrenceException: {
type: DataTypes.STRING,
},
roomId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: "kendoui_resources",
key: "value",
},
onDelete: "CASCADE", // This will delete all appointments referencing the resource when it's deleted
},
isAllDay: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
},
{
tableName: "kendoui_appointments",
timestamps: false,
indexes: [
{
fields: ["start", "end"],
},
],
}
);

import { DataTypes } from 'sequelize';
import sequelize from '../config/database.js';

const KendoUIAppointment = sequelize.define(
'KendoUIAppointment',
{
meetingID : {
type : DataTypes.INTEGER,
primaryKey : true,
autoIncrement : true
},
title : {
type : DataTypes.STRING,
allowNull : false
},
start : {
type : DataTypes.DATE,
defaultValue : null
},
end : {
type : DataTypes.DATE,
defaultValue : null
},
startTimezone : {
type : DataTypes.STRING
},
endTimezone : {
type : DataTypes.STRING
},
description : {
type : DataTypes.STRING
},
recurrenceID : {
type : DataTypes.STRING
},
recurrenceRule : {
type : DataTypes.STRING
},
recurrenceException : {
type : DataTypes.STRING
},
roomId : {
type : DataTypes.INTEGER,
allowNull : false,
references : {
model : 'kendoui_resources',
key : 'value'
},
onDelete : 'CASCADE' // This will delete all appointments referencing the resource when it's deleted
},
isAllDay : {
type : DataTypes.BOOLEAN,
defaultValue : false
}
},
{
tableName : 'kendoui_appointments',
timestamps : false,
indexes : [
{
fields : ['start', 'end']
}
]
}
);

export default KendoUIAppointment;
54 changes: 27 additions & 27 deletions models/KendoUIResource.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { DataTypes } from "sequelize";
import sequelize from "../config/database.js";

const KendoUIResource = sequelize.define(
"KendoUIResource",
{
value: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
text: {
type: DataTypes.STRING,
allowNull: false,
},
color: {
type: DataTypes.STRING,
defaultValue: null,
},
},
{
tableName: "kendoui_resources",
timestamps: false,
}
);

export default KendoUIResource;
import { DataTypes } from 'sequelize';
import sequelize from '../config/database.js';

const KendoUIResource = sequelize.define(
'KendoUIResource',
{
value : {
type : DataTypes.INTEGER,
primaryKey : true,
autoIncrement : true
},
text : {
type : DataTypes.STRING,
allowNull : false
},
color : {
type : DataTypes.STRING,
defaultValue : null
}
},
{
tableName : 'kendoui_resources',
timestamps : false
}
);

export default KendoUIResource;
14 changes: 7 additions & 7 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import KendoUIResource from "./KendoUIResource.js";
import KendoUIAppointment from "./KendoUIAppointment.js";

export {
KendoUIResource,
KendoUIAppointment,
};
import KendoUIResource from './KendoUIResource.js';
import KendoUIAppointment from './KendoUIAppointment.js';

export {
KendoUIResource,
KendoUIAppointment
};
Loading

0 comments on commit 32ffd39

Please sign in to comment.