Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added todo model, updated readme #31

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Install mongoDB
* Start the mongoDB service
* Enter credentials into the .env.sample file and rename it to .env or do git secret reveal if you are a member
* Run `npm install`
* Run `npm ci`
* On one terminal session run `npm run watch-ts`
* On another terminal session run `npm run watch-node`
* View at `localhost:3000`

* Donot run `npm install` since this will update the package-lock.json file and create discrepancies
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.4'

services:
database:
image: "${REGISTRY_NAME}mongo:4.4.3-bionic"
image: "${REGISTRY_NAME}mongo:4.4.6-bionic"
volumes:
- clubdb:/data/db
networks:
Expand Down
1,156 changes: 885 additions & 271 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"fix": "gts fix",
"pretest": "npm run compile",
"posttest": "npm run check",
"eslint-test": "eslint './src/*.ts'",
"eslint-fix": "eslint --fix './src/*.ts'",
"prettier-test": "prettier --check './src/*.ts'",
"prettier-fix": "prettier --write './src/*.ts'",
"eslint-test": "eslint \"./src/*.ts\"",
"eslint-fix": "eslint --fix \"./src/*.ts\"",
"prettier-test": "prettier --check \"./src/*.ts\"",
"prettier-fix": "prettier --write \"./src/*.ts\"",
"lint-tests": "npm run eslint-test;npm run prettier-test",
"lint-fixes": "npm run eslint-fix;npm run prettier-fix"
},
Expand Down Expand Up @@ -57,6 +57,7 @@
"cors": "^2.8.5",
"dotenv": "^8.0.0",
"errorhandler": "^1.5.1",
"eslint": "^7.30.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint is devDependency. So place it in devDependency only and not under dependencies .

"express": "^4.17.1",
"helmet": "^3.23.3",
"jsonwebtoken": "^8.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import logRequest from './middlewares/logRequest';
import userRouter from './controllers/user';
import projectRouter from './controllers/project';
import eventRouter from './controllers/event';
import itemRouter from './controllers/item';
import itemRouter from './controllers/todo';
import resourceRouter from './controllers/resource';

import init from './utils/init';
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/item.ts → src/controllers/todo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import Item from '../models/item';
import Todo from '../models/todo';
import initCRUD from '../utils/crudFactory';
import {Request, Response, NextFunction} from 'express';
import {createResponse, createError} from '../utils/helper';
Expand All @@ -14,7 +14,7 @@ const {
all_query,
all_delete,
delete_query,
} = initCRUD(Item);
} = initCRUD(Todo);

const delete_record = (req: Request, res: Response, next: NextFunction) => {
res.locals.no_send = true;
Expand Down
11 changes: 10 additions & 1 deletion src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,18 @@ const update_record = async (
);
}

// Workaround for when initial approval happens. At that time casi_email
// would be same as that in db, but the addition of roles needs to be done
// So in that case we make the old casi email to be empty string so it is
// different from the new one
let casi_email: string = doc.get('casi_email');
if (doc.get('privelege_level') == 'Unapproved_User') {
casi_email = '';
}

const casiUpdateRes = await updateCASIEmail(
res,
doc.get('casi_email'),
casi_email,
req.body.casi_email
);

Expand Down
41 changes: 15 additions & 26 deletions src/models/item.ts → src/models/todo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';

const itemSchema = new mongoose.Schema(
const todoSchema = new mongoose.Schema(
{
parentId: {
type: mongoose.Schema.Types.ObjectId,
Expand All @@ -18,28 +18,32 @@ const itemSchema = new mongoose.Schema(
required: true,
trim: true,
},
type: {
type: String,
required: true,
lowercase: true,
trim: true,
enum: ['project', 'event', 'resource'],
},

due_date: {
type: Date,
},
assignee: {
assigned_to: {
type: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
},
],
},
assigned_by: {
type: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
},
],
},

status: {
type: String,
trim: true,
required: true,
enum: ['ongoing','completed','upcoming'],
},
labels: {
type: [
Expand All @@ -50,24 +54,9 @@ const itemSchema = new mongoose.Schema(
},
],
},
completed: {
type: Boolean,
required: true,
default: false,
},
created_by: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
// required: true
},
updated_by: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
// required: true
},
},
{timestamps: true}
);

const item = mongoose.model('Item', itemSchema);
export default item;
const todo = mongoose.model('Todo', todoSchema);
export default todo;
2 changes: 1 addition & 1 deletion src/utils/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Item from '../models/item';
import Item from '../models/todo';
import User from '../models/user';
import Project from '../models/project';
import Event from '../models/event';
Expand Down