Skip to content

Commit

Permalink
Merge branch 'main' into refactor/case-insensitive-usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulijuz committed Nov 7, 2024
2 parents 039e741 + dc2bed8 commit decb446
Show file tree
Hide file tree
Showing 310 changed files with 6,727 additions and 1,954 deletions.
868 changes: 524 additions & 344 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@fortawesome/free-brands-svg-icons": "^6.6.0",
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/react-fontawesome": "^0.2.2",
"@prisma/client": "^5.18.0",
"@react-email/components": "^0.0.22",
"@prisma/client": "^5.21.1",
"@react-email/components": "^0.0.25",
"@react-email/render": "^1.0.1",
"bcrypt": "^5.1.1",
"html5-qrcode": "^2.3.8",
Expand All @@ -28,39 +28,39 @@
"next": "^14.2.5",
"next-auth": "^4.24.7",
"next-qrcode": "^2.5.1",
"nodemailer": "^6.9.14",
"nodemailer": "^6.9.15",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-fontawesome": "^1.7.1",
"react-intersection-observer": "^9.13.0",
"react-intersection-observer": "^9.13.1",
"react-pdf": "^9.1.1",
"react-simplemde-editor": "^5.2.0",
"rehype-format": "^5.0.0",
"rehype-stringify": "^10.0.0",
"rehype-format": "^5.0.1",
"rehype-stringify": "^10.0.1",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.0",
"sass": "^1.77.8",
"remark-rehype": "^11.1.1",
"sass": "^1.80.3",
"server-only": "^0.0.1",
"sharp": "^0.33.5",
"unified": "^11.0.5",
"uuid": "^10.0.0",
"winston": "^3.14.2",
"winston": "^3.15.0",
"winston-daily-rotate-file": "^5.0.0",
"zod": "^3.23.8",
"zod-form-data": "^2.0.2"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/jsonwebtoken": "^9.0.6",
"@types/jsonwebtoken": "^9.0.7",
"@types/luxon": "^3.4.2",
"@types/node": "^22.7.5",
"@types/nodemailer": "^6.4.15",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/node": "^22.7.7",
"@types/nodemailer": "^6.4.16",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@types/uuid": "^10.0.0",
"eslint": "^8.57.1",
"eslint-config-next": "^14.2.15",
"prisma": "^5.18.0",
"typescript": "^5.5.4"
"prisma": "^5.21.1",
"typescript": "^5.6.3"
}
}
58 changes: 58 additions & 0 deletions src/actions/Action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { createZodActionError } from './error'
import { safeServerCall } from './safeServerCall'
import { Session } from '@/auth/Session'
import type { SessionMaybeUser } from '@/auth/Session'
import type { ServiceMethod } from '@/services/ServiceTypes'

export function Action<
TypeType,
DetailedType,
Params,
Return,
WantsToOpenTransaction extends boolean,
NoAuther extends boolean
>(serviceMethod: ServiceMethod<
true,
TypeType,
DetailedType,
Params,
Return,
WantsToOpenTransaction,
NoAuther
>) {
return async (params: Params, rawData: FormData) => {
const session = await Session.fromNextAuth()
const parse = serviceMethod.typeValidate(rawData)
if (!parse.success) return createZodActionError(parse)
const data = parse.data
const config: { session: SessionMaybeUser, params: Params, data: DetailedType } = { session, params, data }
return {
...(await safeServerCall(() => serviceMethod.client('NEW').execute(config, { withAuth: true }))),
session: session.toJsObject()
}
}
}

export function ActionNoData<
Params,
Return,
WantsToOpenTransaction extends boolean,
NoAuther extends boolean
>(serviceMethod: ServiceMethod<
false,
never,
never,
Params,
Return,
WantsToOpenTransaction,
NoAuther
>) {
return async (params: Params) => {
const session = await Session.fromNextAuth()
const config: { session: SessionMaybeUser, params: Params, data: unknown } = { session, params, data: {} }
return {
...(await safeServerCall(() => serviceMethod.client('NEW').execute(config, { withAuth: true }))),
session: session.toJsObject()
}
}
}
8 changes: 3 additions & 5 deletions src/actions/Types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { AuthStatus } from '@/auth/getUser'
import type { ServerErrorCode, ErrorMessage } from '@/services/error'

export type ActionErrorCode = ServerErrorCode | AuthStatus
import type { ErrorMessage, ErrorCode } from '@/services/error'

export type ActionReturnError = {
success: false,
errorCode: ActionErrorCode,
errorCode: ErrorCode,
httpCode: number,
error?: ErrorMessage[],
}

Expand Down
5 changes: 5 additions & 0 deletions src/actions/career/companies/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { Action } from '@/actions/Action'
import { Companies } from '@/services/career/companies'

export const createCompanyAction = Action(Companies.create)
5 changes: 5 additions & 0 deletions src/actions/career/companies/destroy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { Companies } from '@/services/career/companies'

export const destroyCompanyAction = ActionNoData(Companies.destory)
5 changes: 5 additions & 0 deletions src/actions/career/companies/read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { Companies } from '@/services/career/companies'

export const readCompanyPageAction = ActionNoData(Companies.readPage)
5 changes: 5 additions & 0 deletions src/actions/career/companies/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { Action } from '@/actions/Action'
import { Companies } from '@/services/career/companies'

export const updateComanyAction = Action(Companies.update)
6 changes: 6 additions & 0 deletions src/actions/career/jobAds/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use server'
import { Action } from '@/actions/Action'
import { JobAds } from '@/services/career/jobAds'

export const createJobAdAction = Action(JobAds.create)

5 changes: 5 additions & 0 deletions src/actions/career/jobAds/destroy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { JobAds } from '@/services/career/jobAds'

export const destroyJobAdAction = ActionNoData(JobAds.destroy)
7 changes: 7 additions & 0 deletions src/actions/career/jobAds/read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { JobAds } from '@/services/career/jobAds'

export const readJobAdAction = ActionNoData(JobAds.read)
export const readActiveJobAdsAction = ActionNoData(JobAds.readActive)
export const readInactiveJobAdsPageAction = ActionNoData(JobAds.readInactivePage)
5 changes: 5 additions & 0 deletions src/actions/career/jobAds/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { Action } from '@/actions/Action'
import { JobAds } from '@/services/career/jobAds'

export const updateJobAdAction = Action(JobAds.update)
6 changes: 6 additions & 0 deletions src/actions/cms/links/read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use server'

import { ActionNoData } from '@/actions/Action'
import { CmsLinks } from '@/services/cms/links'

export const readSpecialCmsLinkAction = ActionNoData(CmsLinks.readSpacial)
5 changes: 5 additions & 0 deletions src/actions/dots/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { Action } from '@/actions/Action'
import { Dots } from '@/services/dots'

export const createDotAction = Action(Dots.create)
7 changes: 7 additions & 0 deletions src/actions/dots/read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { Dots } from '@/services/dots'

export const readDotPage = ActionNoData(Dots.readPage)

export const readDotWrapperForUser = ActionNoData(Dots.readWrapperForUser)
17 changes: 14 additions & 3 deletions src/actions/error.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import type { ErrorMessage } from '@/services/error'
import { errorCodes, type ErrorCode, type ErrorMessage } from '@/services/error'
import type { AuthStatus } from '@/auth/getUser'
import type { SafeParseError } from 'zod'
import type { ActionReturnError, ActionErrorCode } from './Types'
import type { ActionReturnError } from './Types'

export function createActionError(errorCode: ActionErrorCode, error?: string | ErrorMessage[]): ActionReturnError {
export function createActionError(errorCode: ErrorCode | AuthStatus, error?: string | ErrorMessage[]): ActionReturnError {
if (errorCode === 'AUTHORIZED' || errorCode === 'AUTHORIZED_NO_USER') {
return {
success: false,
errorCode: 'UNKNOWN ERROR',
httpCode: 500,
error: typeof error === 'string' ? [{ message: error }] : error,
}
}
return {
success: false,
errorCode,
httpCode: errorCodes.find(e => e.name === errorCode)?.httpCode ?? 500,
error: typeof error === 'string' ? [{ message: error }] : error,
}
}

export function createZodActionError<T>(parse: SafeParseError<T>): ActionReturnError {
return {
success: false,
httpCode: 400,
errorCode: 'BAD PARAMETERS',
error: parse.error.issues,
}
Expand Down
2 changes: 2 additions & 0 deletions src/actions/events/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { safeServerCall } from '@/actions/safeServerCall'
import { Session } from '@/auth/Session'

export async function createEventAction(rawData: FormData) {
console.log('createEventAction')
const parse = Events.create.typeValidate(rawData)
if (!parse.success) return createZodActionError(parse)
const data = parse.data
console.log('createEventAction', data)

const session = await Session.fromNextAuth()

Expand Down
17 changes: 3 additions & 14 deletions src/actions/events/read.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { safeServerCall } from '@/actions/safeServerCall'
import { Session } from '@/auth/Session'
import { Events } from '@/services/events'
import type { ReadPageInput } from '@/services/paging/Types'
import type { EventArchiveCursor, EventArchiveDetails } from '@/services/events/Types'

export async function readCurrentEvents() {
const session = await Session.fromNextAuth()
return await safeServerCall(() => Events.readCurrent.client('NEW').execute({
params: { tags: null, visibilityFilter: {} }, session,
}))
}
export const readCurrentEventsAction = ActionNoData(Events.readCurrent)

export async function readEvent(params: {order: number, name: string}) {
const session = await Session.fromNextAuth()
return await safeServerCall(() => Events.read.client('NEW').execute({ params, session }))
}

export async function readArchivedEventsPage<const PageSize extends number>(
paging: ReadPageInput<PageSize, EventArchiveCursor, EventArchiveDetails>
) {
const session = await Session.fromNextAuth()
return await safeServerCall(() => Events.readArchivedPage.client('NEW').execute({ session, params: { paging } }))
}
export const readArchivedEventsPage = ActionNoData(Events.readArchivedPage)
5 changes: 5 additions & 0 deletions src/actions/events/tags/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { EventTags } from '@/services/events/tags'
import { Action } from '@/actions/Action'

export const createEventTagAction = Action(EventTags.create)
5 changes: 5 additions & 0 deletions src/actions/events/tags/destroy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { EventTags } from '@/services/events/tags'

export const destroyEventTagAction = ActionNoData(EventTags.destroy)
7 changes: 7 additions & 0 deletions src/actions/events/tags/read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server'
import { ActionNoData } from '@/actions/Action'
import { EventTags } from '@/services/events/tags'

export const readEventTagsAction = ActionNoData(EventTags.readAll)
export const readSpecialEventTagAction = ActionNoData(EventTags.readSpecial)
export const readEventTagAction = ActionNoData(EventTags.read)
5 changes: 5 additions & 0 deletions src/actions/events/tags/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'
import { Action } from '@/actions/Action'
import { EventTags } from '@/services/events/tags'

export const updateEventTagAction = Action(EventTags.update)
33 changes: 30 additions & 3 deletions src/actions/groups/committees/read.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
'use server'
import { createActionError } from '@/actions/error'
import { getUser } from '@/auth/getUser'
import { readCommittee, readCommittees } from '@/services/groups/committees/read'
import {
readCommittee,
readCommitteeArticle,
readCommitteeParagraph,
readCommittees
} from '@/services/groups/committees/read'
import { safeServerCall } from '@/actions/safeServerCall'
import type { ExpandedCommittee } from '@/services/groups/committees/Types'
import type { ExpandedArticle } from '@/services/cms/articles/Types'
import type { ExpandedCommittee, ExpandedCommitteeWithCover } from '@/services/groups/committees/Types'
import type { ActionReturn } from '@/actions/Types'
import type { CmsParagraph } from '@prisma/client'

/**
* Reads all committees
Expand All @@ -23,7 +30,7 @@ export async function readCommitteeAction(
data: {
shortName: string
},
): Promise<ActionReturn<ExpandedCommittee>> {
): Promise<ActionReturn<ExpandedCommitteeWithCover>> {
const { authorized, status } = await getUser({
requiredPermissions: [['COMMITTEE_READ']]
})
Expand All @@ -32,3 +39,23 @@ export async function readCommitteeAction(

return await safeServerCall(() => readCommittee(data))
}

export async function readCommitteeArticleAction(shortName: string): Promise<ActionReturn<ExpandedArticle>> {
const { authorized, status } = await getUser({
requiredPermissions: [['COMMITTEE_READ']]
})

if (!authorized) return createActionError(status)

return await safeServerCall(() => readCommitteeArticle(shortName))
}

export async function readCommitteeParagraphAction(shortName: string): Promise<ActionReturn<CmsParagraph>> {
const { authorized, status } = await getUser({
requiredPermissions: [['COMMITTEE_READ']]
})

if (!authorized) return createActionError(status)

return await safeServerCall(() => readCommitteeParagraph(shortName))
}
25 changes: 0 additions & 25 deletions src/actions/jobAds/create.ts

This file was deleted.

Loading

0 comments on commit decb446

Please sign in to comment.