Skip to content

Commit 4e61e22

Browse files
committed
refactor: Few more files to täsä
1 parent ab1aadb commit 4e61e22

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

src/server/models/organisation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
InferAttributes,
1111
InferCreationAttributes,
1212
CreationOptional,
13+
HasManyGetAssociationsMixin,
1314
} from 'sequelize'
1415
import type { LocalizedString } from '@common/types/common'
1516
import { sequelize } from '../db/dbConnection'
@@ -18,6 +19,7 @@ import type { CourseUnit } from './courseUnit'
1819
import type { CourseRealisationsOrganisation } from './courseRealisationsOrganisation'
1920
import type { Tag } from './tag'
2021
import { CourseUnitsOrganisation } from './courseUnitsOrganisation'
22+
import type { User } from './user'
2123

2224
class Organisation extends Model<InferAttributes<Organisation>, InferCreationAttributes<Organisation>> {
2325
// --- Acual DB columns ---
@@ -44,6 +46,8 @@ class Organisation extends Model<InferAttributes<Organisation>, InferCreationAtt
4446
declare tags?: Tag[]
4547
declare childOrganisations?: Organisation[]
4648

49+
declare getUsers: HasManyGetAssociationsMixin<User>
50+
4751
// --- Helper methods ---
4852
// ----------------------
4953
async getCourseCodes() {

src/server/models/user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
InferCreationAttributes,
1010
CreationOptional,
1111
HasManyGetAssociationsMixin,
12+
HasManyHasAssociationMixin,
1213
} from 'sequelize'
1314
import _ from 'lodash'
1415
import { LanguageId } from '@common/types/common'
@@ -47,6 +48,7 @@ class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
4748
declare iamGroups?: string[]
4849

4950
declare getOrganisations: HasManyGetAssociationsMixin<Organisation>
51+
declare hasOrganisation: HasManyHasAssociationMixin<Organisation, string>
5052

5153
async isTeacher() {
5254
const teachings = await UserFeedbackTarget.findAll({

src/server/routes/organisations/feedbackCorrespondentController.js renamed to src/server/routes/organisations/feedbackCorrespondentController.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const { Router } = require('express')
2-
const { User, OrganisationFeedbackCorrespondent } = require('../../models')
3-
const { ApplicationError } = require('../../util/customErrors')
4-
const { getAccessAndOrganisation } = require('./util')
5-
const { createOrganisationLog } = require('../../services/auditLog')
6-
const { ENABLE_CORRESPONDENT_MANAGEMENT } = require('../../util/config')
7-
8-
const addOrganisationFeedbackCorrespondent = async (req, res) => {
1+
import { Response, Router } from 'express'
2+
import { User, OrganisationFeedbackCorrespondent } from '../../models'
3+
import { ApplicationError } from '../../util/customErrors'
4+
import { getAccessAndOrganisation } from './util'
5+
import { createOrganisationLog } from '../../services/auditLog'
6+
import { ENABLE_CORRESPONDENT_MANAGEMENT } from '../../util/config'
7+
import { AuthenticatedRequest } from '../../types'
8+
9+
const addOrganisationFeedbackCorrespondent = async (req: AuthenticatedRequest, res: Response) => {
910
const { user } = req
1011
const { code } = req.params
1112
const { userId } = req.body
@@ -16,10 +17,10 @@ const addOrganisationFeedbackCorrespondent = async (req, res) => {
1617

1718
const userToAdd = await User.findByPk(userId)
1819
if (!userToAdd) {
19-
throw new ApplicationError(`User not found`, 400)
20+
throw new ApplicationError('User not found', 400)
2021
}
2122
if (await userToAdd.hasOrganisation(organisation)) {
22-
throw new ApplicationError(`User already is feedback correspondent of that organisation`, 400)
23+
throw new ApplicationError('User already is feedback correspondent of that organisation', 400)
2324
}
2425

2526
await OrganisationFeedbackCorrespondent.create({
@@ -36,10 +37,10 @@ const addOrganisationFeedbackCorrespondent = async (req, res) => {
3637

3738
const users = await organisation.getUsers()
3839

39-
return res.send(users)
40+
res.send(users)
4041
}
4142

42-
const removeOrganisationFeedbackCorrespondent = async (req, res) => {
43+
const removeOrganisationFeedbackCorrespondent = async (req: AuthenticatedRequest, res: Response) => {
4344
const { user } = req
4445
const { code, userId } = req.params
4546

@@ -70,14 +71,12 @@ const removeOrganisationFeedbackCorrespondent = async (req, res) => {
7071

7172
const users = await organisation.getUsers()
7273

73-
return res.send(users)
74+
res.send(users)
7475
}
7576

76-
const router = Router()
77+
export const router = Router()
7778

7879
if (ENABLE_CORRESPONDENT_MANAGEMENT) {
7980
router.post('/:code/feedback-correspondents', addOrganisationFeedbackCorrespondent)
8081
router.delete('/:code/feedback-correspondents/:userId', removeOrganisationFeedbackCorrespondent)
8182
}
82-
83-
module.exports = router

src/server/routes/tags/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/server/routes/tags/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { router as tagsRouter } from './tags'

0 commit comments

Comments
 (0)