-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'non-next-dependent-api-lib' into updating-api-lib
- Loading branch information
Showing
7 changed files
with
122 additions
and
55 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
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,7 +1,7 @@ | ||
import ApiLib from "./ApiLib"; | ||
|
||
export class SlackNotLinkedError extends ApiLib.Errors.Error { | ||
constructor(res: ApiLib.ApiResponse<any>) { | ||
constructor(res: ApiLib.NextResponse<any>) { | ||
super(res, 400, "Team has not provided a Slack webhook"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import ApiLib from "./ApiLib"; | ||
import { OmitCallSignature } from "../Types"; | ||
|
||
namespace NextApiAdapter { | ||
export class NextResponse<TSend> implements ApiLib.ApiResponse<TSend> { | ||
constructor(public innerRes: NextApiResponse) {} | ||
|
||
send(data: TSend | ApiLib.Errors.ErrorType) { | ||
this.innerRes.send(data); | ||
return this; | ||
} | ||
|
||
status(code: number) { | ||
this.innerRes.status(code); | ||
return this; | ||
} | ||
|
||
error(code: number, message: string) { | ||
this.innerRes.status(code).send({ error: message }); | ||
return this; | ||
} | ||
} | ||
|
||
export function createRoute< | ||
TArgs extends Array<any>, | ||
TReturn, | ||
TDependencies, | ||
TFetchedDuringAuth, | ||
>( | ||
server: Omit< | ||
OmitCallSignature< | ||
ApiLib.Route< | ||
TArgs, | ||
TReturn, | ||
TDependencies, | ||
TFetchedDuringAuth, | ||
NextApiRequest | ||
> | ||
>, | ||
"subUrl" | ||
>, | ||
clientHandler?: (...args: any) => Promise<any>, | ||
): ApiLib.Route< | ||
TArgs, | ||
TReturn, | ||
TDependencies, | ||
TFetchedDuringAuth, | ||
NextApiRequest | ||
> { | ||
return ApiLib.createRoute(server, clientHandler); | ||
} | ||
|
||
export abstract class ServerApi<TDependencies> extends ApiLib.ServerApi< | ||
TDependencies, | ||
NextApiRequest, | ||
NextResponse<unknown> | ||
> { | ||
protected parseRawResponse(rawRes: any): NextResponse<unknown> { | ||
return new NextResponse(rawRes); | ||
} | ||
} | ||
} |
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