Skip to content

Commit 00e0f7a

Browse files
committed
fix seeding and helpers
1 parent c2f70ca commit 00e0f7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1831
-2061
lines changed

package-lock.json

Lines changed: 13 additions & 436 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"@octokit/graphql": "^7.0.1",
6262
"@octokit/rest": "^19.0.13",
6363
"@types/node-cron": "^3.0.11",
64-
"apollo-server": "^3.13.0",
6564
"axios": "^1.7.7",
6665
"bcryptjs": "^2.4.3",
6766
"cloudinary": "^1.30.1",
@@ -88,7 +87,8 @@
8887
"ts-node-dev": "^2.0.0",
8988
"tslog": "^4.9.2",
9089
"ws": "^8.11.0",
91-
"xlsx": "^0.18.5"
90+
"xlsx": "^0.18.5",
91+
"zod": "^3.23.8"
9292
},
9393
"devDependencies": {
9494
"@istanbuljs/nyc-config-typescript": "^1.0.1",

src/helpers/generateRandomPassword.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export default function generateRandomPassword(length = 8) {
44
return generator.generate({
55
length,
66
numbers: true,
7+
symbols: true,
78
});
89
}

src/helpers/isAssignedToProgramOrCohort.ts

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

src/helpers/logintracker.ts

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

src/helpers/organization.helper.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { GraphQLError } from 'graphql'
22
import 'dotenv/config'
33
import { JwtPayload, verify } from 'jsonwebtoken'
4-
import { Organization } from '../models/organization.model'
4+
import { IOrganizationSchema, Organization } from '../models/organization.model'
5+
import { OrgUserDataInterface, UserInterface } from '../models/user'
6+
import { HydratedDocument } from 'mongoose'
57

68
export async function checkLoggedInOrganization(token?: string) {
79
const SECRET = process.env.SECRET as string
@@ -27,6 +29,14 @@ export async function checkLoggedInOrganization(token?: string) {
2729
})
2830
}
2931

32+
if(org.isDeleted){
33+
throw new GraphQLError(`Organization named ${name} was deleted`, {
34+
extensions: {
35+
code: 'AUTHENTICATION_ERROR',
36+
},
37+
})
38+
}
39+
3040
return org
3141
} catch (error: any) {
3242
if (error.message === 'invalid signature') {
@@ -50,3 +60,15 @@ export async function checkLoggedInOrganization(token?: string) {
5060
}
5161
}
5262
}
63+
64+
export function isPartOfOrganization(user: UserInterface, org: HydratedDocument<IOrganizationSchema>): OrgUserDataInterface{
65+
const orgUserData = user.organizations.find(data=>data.orgId.toString()===org._id.toString())
66+
if(!orgUserData){
67+
throw new GraphQLError(`User ${user.email} is not part of ${org.name}`,{
68+
extensions: {
69+
code: "FORBIDDEN"
70+
}
71+
})
72+
}
73+
return orgUserData
74+
}

0 commit comments

Comments
 (0)