Skip to content

Commit

Permalink
Merge pull request #562 from encorelab/develop
Browse files Browse the repository at this point in the history
Master <- Develop
  • Loading branch information
JoelWiebe authored Jul 27, 2023
2 parents bf1e5fa + e582667 commit 862a60e
Show file tree
Hide file tree
Showing 33 changed files with 398 additions and 258 deletions.
7 changes: 7 additions & 0 deletions backend/src/api/learner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ router.post('/board/many', async (req, res) => {
res.status(200).json(models);
});

router.post('/project/many', async (req, res) => {
const { projectIDs } = req.body;

const models = await dalLearnerModel.getByProjects(projectIDs);
res.status(200).json(models);
});

router.post('/:id/addDimension', async (req, res) => {
const { id } = req.params;
const { dimension } = req.body;
Expand Down
16 changes: 12 additions & 4 deletions backend/src/api/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,18 @@ router.post('/task/groupTask/:groupTaskID/submit', async (req, res) => {

// if post from board => move to list view
// if post from bucket => delete from bucket
if (workflow.source.type === ContainerType.BOARD) {
await dalPost.update(post, { type: PostType.LIST });
} else if (workflow.source.type === ContainerType.BUCKET) {
await dalBucket.removePost(workflow.source.id, [post]);
if (workflow.source.type === ContainerType.WORKFLOW) {
if (destination.type === ContainerType.BOARD) {
await dalPost.update(post, { type: PostType.BOARD });
} else {
await dalPost.update(post, { type: PostType.BUCKET });
}
} else {
if (workflow.source.type === ContainerType.BOARD) {
await dalPost.update(post, { type: PostType.LIST });
} else if (workflow.source.type === ContainerType.BUCKET) {
await dalBucket.removePost(workflow.source.id, [post]);
}
}

Socket.Instance.emit(SocketEvent.WORKFLOW_POST_SUBMIT, post, true);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/models/Learner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class LearnerModelModel {
@prop({ required: true })
public projectID!: string;

@prop({ required: true })
public boardID!: string;
@prop({ required: false })
public boardID?: string;

@prop({ required: true })
public name!: string;
Expand Down
1 change: 1 addition & 0 deletions backend/src/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum PostType {
BOARD = 'BOARD',
BUCKET = 'BUCKET',
LIST = 'LIST',
WORKFLOW = 'WORKFLOW',
}

export class MultipleChoiceOptions {
Expand Down
1 change: 1 addition & 0 deletions backend/src/models/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum DistributionWorkflowType {
export enum ContainerType {
BOARD = 'BOARD',
BUCKET = 'BUCKET',
WORKFLOW = 'WORKFLOW',
}

export enum TaskActionType {
Expand Down
2 changes: 0 additions & 2 deletions backend/src/repository/dalBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import dalProject from './dalProject';
import dalTag from './dalTag';
import dalComment from './dalComment';
import dalVote from './dalVote';
import dalLearnerModel from './dalLearnerModel';

export const getById = async (id: string) => {
try {
Expand Down Expand Up @@ -69,7 +68,6 @@ export const getAllPersonal = async (projectID: string) => {
export const create = async (board: BoardModel) => {
try {
const savedBoard = await Board.create(board);
await dalLearnerModel.createDefaultModels(board.projectID, board.boardID);
return savedBoard;
} catch (err) {
throw new Error(JSON.stringify(err, null, ' '));
Expand Down
16 changes: 11 additions & 5 deletions backend/src/repository/dalLearnerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ export const create = async (
}
};

export const createDefaultModels = async (
projectID: string,
boardID: string
) => {
export const createDefaultModels = async (projectID: string) => {
try {
for (const value of DEFAULT_MODELS) {
await Learner.create({
modelID: new mongo.ObjectId().toString(),
projectID: projectID,
boardID: boardID,
name: value,
dimensions: [],
data: [],
Expand All @@ -57,6 +53,15 @@ export const getByID = async (modelID: string) => {
}
};

export const getByProjects = async (projectIDs: string[]) => {
try {
const models = await Learner.find({ projectID: { $in: projectIDs } });
return models;
} catch (err) {
throw new Error(JSON.stringify(err, null, ' '));
}
};

export const getByBoards = async (boardIDs: string[]) => {
try {
const models = await Learner.find({ boardID: { $in: boardIDs } });
Expand Down Expand Up @@ -185,6 +190,7 @@ const dalLearnerModel = {
createDefaultModels,
getByID,
getByBoards,
getByProjects,
addDimension,
removeDimension,
addDimensionValues,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/repository/dalProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UnauthorizedError } from '../errors/client.errors';
import Project, { ProjectModel } from '../models/Project';
import mongoose from 'mongoose';
import dalBoard from './dalBoard';
import dalLearnerModel from './dalLearnerModel';
import { Role } from '../models/User';

export const getById = async (id: string) => {
Expand Down Expand Up @@ -57,6 +58,7 @@ export const addTeacher = async (code: string, userID: string) => {
export const create = async (project: ProjectModel) => {
try {
const savedProject = await Project.create(project);
await dalLearnerModel.createDefaultModels(project.projectID);
return savedProject;
} catch (err) {
throw new Error(JSON.stringify(err, null, ' '));
Expand Down
Loading

0 comments on commit 862a60e

Please sign in to comment.