Skip to content

Commit

Permalink
Feat: added initial migration script
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
Akalanka47000 committed Aug 13, 2023
1 parent 97eac09 commit c88134c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import crypto from 'crypto';
import express from 'express';
import context from 'express-http-context';
import rateLimit from 'express-rate-limit';
import httpLogger from '@sliit-foss/http-logger';
import { moduleLogger } from '@sliit-foss/module-logger';
import compression from 'compression';
import cors from 'cors';
import crypto from 'crypto';
import helmet from 'helmet';
import { pick } from 'lodash';
import { default as connectDB } from '@/database';
Expand Down
16 changes: 16 additions & 0 deletions src/database/migrations/20230812121853-create_initial_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
async up(db) {
await db.collection('settings').deleteMany({});
await db.collection('settings').insertOne({
submission_deadline: new Date('2023-09-21T12:00:00.000Z'),
registration_deadline: new Date('2023-09-14T12:00:00.000Z'),
created_at: new Date(),
updated_at: new Date(),
__v: 0
});
},

async down(db) {
await db.collection('settings').deleteMany({});
}
};
4 changes: 2 additions & 2 deletions src/routes/index.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import authRouter from './auth.routes';
import dashboardRouter from './dashboard.routes';
import leaderboardRouter from './leaderboard.routes';
import questionRouter from './question.routes';
import settingsRouter from './settings.routes';
import settingRouter from './setting.routes';
import submissionRouter from './submission.routes';
import userRouter from './user.routes';
import { adminProtect, protect } from '@/middleware/auth';
Expand All @@ -16,6 +16,6 @@ router.use('/users', protect, userRouter);
router.use('/questions', protect, questionRouter);
router.use('/dashboard', protect, adminProtect, dashboardRouter);
router.use('/leaderboard', leaderboardRouter);
router.use('/settings', protect, adminProtect, settingsRouter);
router.use('/settings', protect, adminProtect, settingRouter);

export default router;
File renamed without changes.
4 changes: 2 additions & 2 deletions src/services/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import crypto from 'crypto';
import bcrypt from 'bcryptjs';
import crypto from 'crypto';
import createError from 'http-errors';
import { sendMail } from './email';
import { createUser, findOneAndUpdateUser, getOneUser } from '@/repository/user';
import { decodeJwtToken } from '@/utils';
import { sendMail } from './email';

export const authRegister = async ({ name, email, password, university, members }) => {
const encryptedPassword = await new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bcrypt from 'bcryptjs';
import createError from 'http-errors';
import { sendMail } from './email';
import { createUser, findOneAndRemoveUser, findOneAndUpdateUser, getAllUsers, getOneUser } from '@/repository/user';
import { sendMail } from './email';

export const getUsers = (query) => {
return getAllUsers(query);
Expand Down
2 changes: 1 addition & 1 deletion src/validations/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Joi } from 'celebrate';

export const updateSettingsSchema = Joi.object.keys({
export const updateSettingsSchema = Joi.object({
submission_deadline: Joi.date().allow(null),
registration_deadline: Joi.date().allow(null)
});

0 comments on commit c88134c

Please sign in to comment.