Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generator #302

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions apps/api-server/src/authentication-handlers/api-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ test('api-key authentication', () =>
userId: userItem.id,
})

const result = await api.client.me(
{
contentType: null,
parameters: {},
},
{ apiKey: apiKeyItem.token },
{ baseUrl },
)
const result = await api.client.me({
apiKey: apiKeyItem.token,
baseUrl,
})

assert(result.status === 200)

Expand Down
9 changes: 1 addition & 8 deletions apps/api-server/src/authentication-handlers/open-id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ test('open-id authentication', () =>

const token = sessionItem.access_token

const result = await api.client.me(
{
contentType: null,
parameters: {},
},
{ openId: token },
{ baseUrl },
)
const result = await api.client.me({ openId: token, baseUrl })

assert(result.status === 200)

Expand Down
11 changes: 2 additions & 9 deletions apps/api-server/src/operation-handlers/curriculum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import * as application from '../application/index.js'

export const retrieveCurriculaByDiscipline: api.server.RetrieveCurriculaByDisciplineOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
// const { disciplineKey } = incomingRequest.parameters

> = async ({ disciplineKey }) => {
// // TODO get discipline type from core
// let disciplineItem: Awaited<
// ReturnType<typeof core.Program.Discipline.fromHandle>
Expand Down Expand Up @@ -35,10 +33,5 @@ export const retrieveCurriculaByDiscipline: api.server.RetrieveCurriculaByDiscip
// id: item.id,
// }))

return {
parameters: {},
status: 200,
contentType: 'application/json',
entity: () => [],
}
return [200, []]
}
19 changes: 4 additions & 15 deletions apps/api-server/src/operation-handlers/discipline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@ import * as application from '../application/index.js'

export const listDisciplines: api.server.ListDisciplinesOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
> = async () => {
// const disciplineList = await core.Program.Discipline.list()

// const responseEntity = disciplineList.map((item) => ({
// id: item.id,
// handle: item.handle,
// }))

return {
parameters: {},
status: 200,
contentType: 'application/json',
entity: () => [],
}
return []
}

export const retrieveDiscipline: api.server.RetrieveDisciplineOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
// const { disciplineKey } = incomingRequest.parameters

> = async ({ disciplineKey }) => {
// // TODO get discipline type from core
// let disciplineItem: Awaited<
// ReturnType<typeof core.Program.Discipline.fromHandle>
Expand Down Expand Up @@ -57,9 +50,5 @@ export const retrieveDiscipline: api.server.RetrieveDisciplineOperationHandler<
// entity: () => responseEntity,
// }

return {
parameters: {},
status: 404,
contentType: null,
}
return [404, undefined]
}
35 changes: 6 additions & 29 deletions apps/api-server/src/operation-handlers/location-certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import * as application from '../application/index.js'

export const getLocationCertificates: api.server.GetLocationCertificatesOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
const { locationKey } = incomingRequest.parameters

> = async ({ locationKey }) => {
// TODO get type from core
let locationItem: Awaited<ReturnType<typeof core.Location.fromHandle>>

Expand All @@ -19,11 +17,7 @@ export const getLocationCertificates: api.server.GetLocationCertificatesOperatio
}

if (locationItem == null) {
return {
parameters: {},
status: 404,
contentType: null,
}
return [404, undefined]
}

// TODO actually list certificates
Expand All @@ -37,21 +31,13 @@ export const getLocationCertificates: api.server.GetLocationCertificatesOperatio
title: item.title,
}))

return {
status: 200,
parameters: {},
contentType: 'application/json',
entity: () => responseEntity,
}
return [200, responseEntity]
}

export const createLocationCertificate: api.server.CreateLocationCertificateOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) =>
> = async ({ locationKey }, requestEntity) =>
core.withTransaction(async () => {
const { locationKey } = incomingRequest.parameters
const requestEntity = await incomingRequest.entity()

// TODO get type from core
let locationItem: Awaited<ReturnType<typeof core.Location.fromHandle>>

Expand All @@ -64,11 +50,7 @@ export const createLocationCertificate: api.server.CreateLocationCertificateOper
}

if (locationItem == null) {
return {
parameters: {},
status: 404,
contentType: null,
}
return [404, undefined]
}

// TODO actually create a certificate
Expand All @@ -82,10 +64,5 @@ export const createLocationCertificate: api.server.CreateLocationCertificateOper
id: certificateItem.id,
}

return {
status: 201,
parameters: {},
contentType: 'application/json',
entity: () => responseItem,
}
return [201, responseItem]
})
28 changes: 7 additions & 21 deletions apps/api-server/src/operation-handlers/location-cohort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import * as application from '../application/index.js'

export const getLocationCohorts: api.server.GetLocationCohortsOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
const { locationKey } = incomingRequest.parameters

> = async ({ locationKey }) => {
// TODO list cohorts

return {
status: 200,
parameters: {},
contentType: 'application/json',
entity: () => [
return [
200,
[
{
id: '',
handle: '',
Expand All @@ -25,24 +21,14 @@ export const getLocationCohorts: api.server.GetLocationCohortsOperationHandler<
title: '',
},
],
}
]
}

export const createLocationCohort: api.server.CreateLocationCohortOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) =>
> = async ({ locationKey }, entity) =>
core.withTransaction(async () => {
const { locationKey } = incomingRequest.parameters
const entity = await incomingRequest.entity()

// TODO create cohort

return {
status: 201,
parameters: {},
contentType: 'application/json',
entity: () => ({
id: '',
}),
}
return [201, { id: '' }]
})
21 changes: 4 additions & 17 deletions apps/api-server/src/operation-handlers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as application from '../application/index.js'

export const getLocations: api.server.GetLocationsOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
> = async () => {
const list = await core.Location.list()

const listEntity = list.map((item) => ({
Expand All @@ -13,21 +13,13 @@ export const getLocations: api.server.GetLocationsOperationHandler<
title: item.name,
}))

// TODO this could be easier
return {
status: 200,
parameters: {},
contentType: 'application/json',
entity: () => listEntity,
}
return listEntity
}

export const createLocation: api.server.CreateLocationOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) =>
> = async (entity) =>
core.withTransaction(async () => {
const entity = await incomingRequest.entity()

const result = await core.Location.create({
name: entity.title,
handle: entity.handle,
Expand All @@ -38,10 +30,5 @@ export const createLocation: api.server.CreateLocationOperationHandler<
id: result.id,
}

return {
status: 201,
parameters: {},
contentType: 'application/json',
entity: () => resultEntity,
}
return [201, resultEntity]
})
11 changes: 3 additions & 8 deletions apps/api-server/src/operation-handlers/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as application from '../application/index.js'

export const me: api.server.MeOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
> = async (authentication) => {
let id: string | undefined
// TODO make this more ergonomic
if ('apiKey' in authentication && authentication.apiKey != null) {
Expand All @@ -19,12 +19,7 @@ export const me: api.server.MeOperationHandler<
assert(id != null)

return {
status: 200,
parameters: {},
contentType: 'application/json',
entity: () => ({
id,
handle: '',
}),
id,
handle: '',
}
}
9 changes: 2 additions & 7 deletions apps/api-server/src/operation-handlers/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as application from '../application/index.js'

export const listPrograms: api.server.ListProgramsOperationHandler<
application.Authentication
> = async (incomingRequest, authentication) => {
> = async () => {
// const list = await core.Program.list()

// const listEntity = list.map((item) => ({
Expand All @@ -16,10 +16,5 @@ export const listPrograms: api.server.ListProgramsOperationHandler<
// disciplineTitle: item.discipline.title,
// }))

return {
status: 200,
parameters: {},
contentType: 'application/json',
entity: () => [],
}
return []
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"formatting": "prettier --check *",
"formatting:fix": "prettier --write *",
"build:packages": "pnpm --recursive --filter './packages/**' build",
"initialize": "node ./scripts/initialize.js",
"initialize": "node ./scripts/initialize.mjs",
"db:reset": "node ./scripts/reset-migrate-local-db.js",
"db:seed": "node ./scripts/seed-local-db.js"
},
Expand Down
Loading
Loading