-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
26 changed files
with
138 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
singleQuote: true | ||
trailingComma: es5 | ||
printWidth: 120 | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"printWidth": 120 | ||
} |
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
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
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,9 +1,11 @@ | ||
import { Middleware } from 'koa'; | ||
import { DatabasePoolType } from 'slonik'; | ||
|
||
export const dbConnection = (pool: DatabasePoolType): Middleware => async (context, next) => { | ||
await pool.connect(async connection => { | ||
context.connection = connection; | ||
await next(); | ||
}); | ||
}; | ||
export const dbConnection = | ||
(pool: DatabasePoolType): Middleware => | ||
async (context, next) => { | ||
await pool.connect(async (connection) => { | ||
context.connection = connection; | ||
await next(); | ||
}); | ||
}; |
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,25 @@ | ||
import { RouteMiddleware } from '../types'; | ||
import { RequestError } from '../errors/request-error'; | ||
|
||
export const requestBody = (schemaName?: string): RouteMiddleware => async (context, next) => { | ||
if (context.request.body) { | ||
if (schemaName === 'create-sub-task') { | ||
const items = Array.isArray(context.request.body) ? context.request.body : [context.request.body]; | ||
for (const body of items) { | ||
const valid = context.ajv.validate('create-task', body); | ||
export const requestBody = | ||
(schemaName?: string): RouteMiddleware => | ||
async (context, next) => { | ||
if (context.request.body) { | ||
if (schemaName === 'create-sub-task') { | ||
const items = Array.isArray(context.request.body) ? context.request.body : [context.request.body]; | ||
for (const body of items) { | ||
const valid = context.ajv.validate('create-task', body); | ||
if (!valid) { | ||
throw new RequestError(context.ajv.errorsText()); | ||
} | ||
} | ||
} else if (schemaName) { | ||
const valid = context.ajv.validate(schemaName, context.request.body); | ||
if (!valid) { | ||
throw new RequestError(context.ajv.errorsText()); | ||
} | ||
} | ||
} else if (schemaName) { | ||
const valid = context.ajv.validate(schemaName, context.request.body); | ||
if (!valid) { | ||
throw new RequestError(context.ajv.errorsText()); | ||
} | ||
context.requestBody = context.request.body; | ||
} | ||
context.requestBody = context.request.body; | ||
} | ||
await next(); | ||
}; | ||
await next(); | ||
}; |
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
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
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
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
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.