Skip to content

Commit

Permalink
fix(attendance): move attendance calculation logic from client to server
Browse files Browse the repository at this point in the history
  • Loading branch information
aimedivin committed Oct 27, 2024
1 parent d3f9075 commit 7fa4f8d
Show file tree
Hide file tree
Showing 14 changed files with 809 additions and 194 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@graphql-tools/utils": "^10.0.4",
"@octokit/graphql": "^7.0.1",
"@octokit/rest": "^19.0.13",
"@types/node-cron": "^3.0.11",
"apollo-server": "^3.13.0",
"bcryptjs": "^2.4.3",
"cloudinary": "^1.30.1",
Expand All @@ -78,6 +79,7 @@
"jsonwebtoken": "^9.0.2",
"mongodb": "^4.17.1",
"mongoose": "^6.6.1",
"node-cron": "^3.0.3",
"node-fetch": "^2.6.12",
"nodemailer": "^6.7.8",
"normalize-mongoose": "^1.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { IResolvers } from '@graphql-tools/utils'
import invitationSchema from './schema/invitation.schema'
import TableViewInvitationResolver from './resolvers/TableViewInvitationResolver'
import eventSchema from './schema/event.schema'
import './utils/cron-jobs/team-jobs'

const PORT: number = parseInt(process.env.PORT!) || 4000

Expand Down
37 changes: 29 additions & 8 deletions src/models/attendance.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,20 @@ const AttendanceSchema = new Schema({

teams: [
{
date: {
type: Date,
required: false,
default: () => {
const date = new Date();
if (date.getUTCHours() >= 22) {
date.setUTCDate(date.getUTCDate() + 1);
date.setUTCHours(0, 0, 0, 0);
}
return date
},
},
team: {
type: mongoose.Types.ObjectId,
type: mongoose.Schema.Types.ObjectId,
ref: 'Team',
required: true
},
Expand All @@ -34,24 +46,33 @@ const AttendanceSchema = new Schema({
day: {
type: String,
enum: ['mon', 'tue', 'wed', 'thu', 'fri'],
required: true
required: true
},
date: {
type: Date,
required: true
required: true
},
score: {
type: String,
enum: ['0', '1', '2'],
required: true
enum: [0, 1, 2],
required: true
},
},
],
},
],}
],
}
],

})
}, { timestamps: true })

AttendanceSchema.index(
{
phase: 1,
cohort: 1,
createdAt: 1
},
{ unique: true }
);

const Attendance = mongoose.model('Attendance', AttendanceSchema)
export { Attendance }
8 changes: 8 additions & 0 deletions src/models/team.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import mongoose, { Schema } from 'mongoose'
import { User } from './user'
import { CohortInterface } from './cohort.model';
import { PhaseInterface } from './phase.model';

export interface TeamInterface {
_id: mongoose.Types.ObjectId;
name: string;
cohort?: CohortInterface;
phase?: PhaseInterface;
ttl?: mongoose.Types.ObjectId;
members: mongoose.Types.ObjectId[];
startingPhase: Date;
Expand Down Expand Up @@ -57,6 +60,11 @@ const teamSchema = new Schema(
type: mongoose.Types.ObjectId,
ref: 'Program',
},
isJobActive: {
type: Boolean,
default: true,
required: true,
},
},
{
statics: {
Expand Down
24 changes: 13 additions & 11 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ export interface UserStatus {
}

export interface UserInterface {
_id: mongoose.Types.ObjectId
email: string
password: string
role: string
team?: mongoose.Types.ObjectId
status: UserStatus
cohort?: mongoose.Types.ObjectId
program?: mongoose.Types.ObjectId
organizations: string[]
pushNotifications: boolean
emailNotifications: boolean
_id: mongoose.Types.ObjectId;
email: string;
password: string;
role: string;
team?: mongoose.Types.ObjectId;
status: UserStatus;
cohort?: mongoose.Types.ObjectId;
program?: mongoose.Types.ObjectId;
organizations: string[];
pushNotifications: boolean;
emailNotifications: boolean;
profile?: mongoose.Types.ObjectId;
ratings?: mongoose.Types.ObjectId[];
}

export enum RoleOfUser {
Expand Down
Loading

0 comments on commit 7fa4f8d

Please sign in to comment.