-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95e46d7
commit bdfdbf6
Showing
18 changed files
with
558 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import handler from "../../libs/handler-lib"; | ||
import { handler } from "../../libs/handler-lib"; | ||
import { parseReportTypeAndState } from "../../libs/param-lib"; | ||
import { badRequest, ok } from "../../libs/response-lib"; | ||
import { badRequest, forbidden, ok } from "../../libs/response-lib"; | ||
import { canWriteState } from "../../utils/authorization"; | ||
import { error } from "../../utils/constants"; | ||
import { buildReport } from "./buildReport"; | ||
|
||
export const createReport = handler(async (event) => { | ||
const { allParamsValid, reportType, state } = parseReportTypeAndState(event); | ||
if (!allParamsValid) { | ||
return badRequest("Invalid path parameters"); | ||
} | ||
export const createReport = handler( | ||
parseReportTypeAndState, | ||
async (request) => { | ||
const { reportType, state } = request.parameters; | ||
const user = request.user; | ||
|
||
// TODO: Auth | ||
const user = ""; | ||
if (!canWriteState(user, state)) { | ||
return forbidden(error.UNAUTHORIZED); | ||
} | ||
|
||
if (!event?.body) { | ||
return badRequest("Invalid request"); | ||
} | ||
// const options = JSON.parse(event.body); | ||
if (!request?.body) { | ||
return badRequest("Invalid request"); | ||
} | ||
// const options = JSON.parse(event.body); | ||
|
||
const report = await buildReport(reportType, state, [], user); | ||
const report = await buildReport(reportType, state, [], user.full_name); | ||
|
||
return ok(report); | ||
}); | ||
return ok(report); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
import handler from "../../libs/handler-lib"; | ||
import { handler } from "../../libs/handler-lib"; | ||
import { | ||
parseReportParameters, | ||
parseReportTypeAndState, | ||
} from "../../libs/param-lib"; | ||
import { badRequest, ok } from "../../libs/response-lib"; | ||
import { forbidden, ok } from "../../libs/response-lib"; | ||
import { | ||
getReport as getReportFromDatabase, | ||
queryReportsForState, | ||
} from "../../storage/reports"; | ||
import { canReadState } from "../../utils/authorization"; | ||
import { error } from "../../utils/constants"; | ||
|
||
export const getReport = handler(async (event) => { | ||
const { allParamsValid, reportType, state, id } = | ||
parseReportParameters(event); | ||
if (!allParamsValid) { | ||
return badRequest("Invalid path parameters"); | ||
} | ||
export const getReport = handler(parseReportParameters, async (request) => { | ||
const { reportType, state, id } = request.parameters; | ||
const user = request.user; | ||
|
||
// TODO: Auth | ||
if (!canReadState(user, state)) { | ||
return forbidden(error.UNAUTHORIZED); | ||
} | ||
|
||
const report = await getReportFromDatabase(reportType, state, id); | ||
|
||
return ok(report); | ||
}); | ||
|
||
export const getReportsForState = handler(async (event) => { | ||
const { allParamsValid, reportType, state } = parseReportTypeAndState(event); | ||
if (!allParamsValid) { | ||
return badRequest("Invalid path parameters"); | ||
} | ||
export const getReportsForState = handler( | ||
parseReportTypeAndState, | ||
async (request) => { | ||
const { reportType, state } = request.parameters; | ||
const user = request.user; | ||
|
||
// TODO: Auth | ||
if (!canReadState(user, state)) { | ||
return forbidden(error.UNAUTHORIZED); | ||
} | ||
|
||
const reports = await queryReportsForState(reportType, state); | ||
const reports = await queryReportsForState(reportType, state); | ||
|
||
return ok(reports); | ||
}); | ||
return ok(reports); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.