strictNullChecks (#4666)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
This commit is contained in:
syuilo
2019-04-13 01:43:22 +09:00
committed by GitHub
parent 4ee40c3345
commit 987168b863
214 changed files with 939 additions and 785 deletions

View File

@@ -12,7 +12,7 @@ const accessDenied = {
id: '56f35758-7dd5-468b-8439-5d6fb8ec9b8e'
};
export default async (endpoint: string, user: User, app: App, data: any, file?: any) => {
export default async (endpoint: string, user: User | null | undefined, app: App | null | undefined, data: any, file?: any) => {
const isSecure = user != null && app == null;
const ep = endpoints.find(e => e.name === endpoint);
@@ -39,15 +39,15 @@ export default async (endpoint: string, user: User, app: App, data: any, file?:
});
}
if (ep.meta.requireCredential && user.isSuspended) {
if (ep.meta.requireCredential && user!.isSuspended) {
throw new ApiError(accessDenied, { reason: 'Your account has been suspended.' });
}
if (ep.meta.requireAdmin && !user.isAdmin) {
if (ep.meta.requireAdmin && !user!.isAdmin) {
throw new ApiError(accessDenied, { reason: 'You are not the admin.' });
}
if (ep.meta.requireModerator && !user.isAdmin && !user.isModerator) {
if (ep.meta.requireModerator && !user!.isAdmin && !user!.isModerator) {
throw new ApiError(accessDenied, { reason: 'You are not a moderator.' });
}
@@ -61,7 +61,7 @@ export default async (endpoint: string, user: User, app: App, data: any, file?:
if (ep.meta.requireCredential && ep.meta.limit) {
// Rate limit
await limiter(ep, user).catch(e => {
await limiter(ep, user!).catch(e => {
throw new ApiError({
message: 'Rate limit exceeded. Please try again later.',
code: 'RATE_LIMIT_EXCEEDED',