Browse Source

fix or disable lint errors

main
eiknat 1 year ago
parent
commit
fa9fbce9c7
  1. 8
      .eslintrc.js
  2. 3
      src/app.ts
  3. 2
      src/category/category.controller.ts
  4. 2
      src/category/category.model.ts
  5. 4
      src/comment/comment.controller.ts
  6. 2
      src/comment/comment.model.ts
  7. 6
      src/community/community.controller.ts
  8. 2
      src/community/community.model.ts
  9. 3
      src/database/knex.ts
  10. 1
      src/database/seeds/00_user_test_data.ts
  11. 1
      src/database/seeds/01_site_test_data.ts
  12. 1
      src/database/seeds/02_category_test_data.ts
  13. 1
      src/database/seeds/03_community_test_data.ts
  14. 1
      src/database/seeds/04_post_test_data.ts
  15. 1
      src/database/seeds/05_comment_test_data.ts
  16. 1
      src/database/seeds/06_private-message_test_data.ts
  17. 1
      src/enums.ts
  18. 2
      src/lib/errors.ts
  19. 5
      src/middleware/errors.middleware.ts
  20. 8
      src/middleware/user.middleware.ts
  21. 2
      src/post/post.controller.ts
  22. 2
      src/post/post.model.ts
  23. 6
      src/private-message/private-message.controller.ts
  24. 2
      src/private-message/private-message.model.ts
  25. 2
      src/site/site.controller.ts
  26. 2
      src/site/site.model.ts
  27. 5
      src/user/models/user-ban.model.ts
  28. 4
      src/user/models/user-mention.model.ts
  29. 4
      src/user/models/user-tag.model.ts
  30. 4
      src/user/models/user-token.model.ts
  31. 14
      src/user/models/user.model.ts
  32. 9
      src/user/user.controller.ts

8
.eslintrc.js

@ -1,6 +1,7 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
},
plugins: [
@ -8,8 +9,13 @@ module.exports = {
],
extends: [
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
rules: {
'max-len': [2, {'code': 120, 'tabWidth': 2, 'ignoreUrls': true}]
'radix': ['error', 'as-needed'],
'max-len': [2, {'code': 120, 'tabWidth': 2, 'ignoreUrls': true}],
'no-trailing-spaces': [2, { 'skipBlankLines': true }],
'arrow-body-style': 'off'
}
};

3
src/app.ts

@ -7,7 +7,6 @@ import { getPrivateMessages } from './private-message/private-message.controller
import { getCommunities } from './community/community.controller';
import { getComments } from './comment/comment.controller';
import { getCategories } from './category/category.controller';
import { requireAdminOrMod, requireUserToken } from './middleware/user.middleware';
import { errorHandler } from './middleware/errors.middleware';
let path = `${__dirname}/.env`;
@ -29,6 +28,7 @@ const app: Application = express();
const port: string = process.env.HB_PORT || '8080';
app.get('/', (req: Request, res: Response) => {
// eslint-disable-next-line no-console
console.log('ping');
res.send('pong');
});
@ -45,5 +45,6 @@ app.use('/api/v1/users', UserRoutes);
app.use(errorHandler);
app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`hexing on port ${port}`);
});

2
src/category/category.controller.ts

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response } from 'express';
import { getCategoryList } from './category.model';

2
src/category/category.model.ts

@ -5,4 +5,4 @@ export interface Category {
name: string;
}
export const getCategoryList = async (): Promise<Category[]> => await knex<Category>('category');
export const getCategoryList = async (): Promise<Category[]> => knex<Category>('category');

4
src/comment/comment.controller.ts

@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response } from 'express';
import { getCommentList } from './comment.model';
export const getComments = async (req: Request, res: Response) => res.json({ comments: await getCommentList() });
export const getComments = async (_req: Request, res: Response) => res.json({ comments: await getCommentList() });

2
src/comment/comment.model.ts

@ -15,4 +15,4 @@ export interface Comment {
local: boolean;
}
export const getCommentList = async (): Promise<Comment[]> => await knex<Comment>('comment');
export const getCommentList = async (): Promise<Comment[]> => knex<Comment>('comment');

6
src/community/community.controller.ts

@ -1,4 +1,8 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response } from 'express';
import { getCommunityList } from './community.model';
export const getCommunities = async (req: Request, res: Response) => res.json({ communities: await getCommunityList() });
export const getCommunities = async (_req: Request, res: Response) => res.json({
communities: await getCommunityList(),
});

2
src/community/community.model.ts

@ -21,4 +21,4 @@ export interface Community {
banner?: string;
}
export const getCommunityList = async (): Promise<Community[]> => await knex<Community>('community');
export const getCommunityList = async (): Promise<Community[]> => knex<Community>('community');

3
src/database/knex.ts

@ -1,4 +1,5 @@
/* eslint-disable import/prefer-default-export */
import Knex from 'knex';
import { default as KnexConfig } from './knexfile';
import KnexConfig from './knexfile';
export const knex = Knex(KnexConfig.development);

1
src/database/seeds/00_user_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/database/seeds/01_site_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/database/seeds/02_category_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/database/seeds/03_community_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/database/seeds/04_post_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/database/seeds/05_comment_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/database/seeds/06_private-message_test_data.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<void> {

1
src/enums.ts

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
export enum SortType {
Active,
Hot,

2
src/lib/errors.ts

@ -7,4 +7,4 @@ export class HTTPError extends Error {
}
}
export const Unauthorized_Error = new HTTPError(401, 'unauthorized');
export const UNAUTHORIZED_ERROR = new HTTPError(401, 'unauthorized');

5
src/middleware/errors.middleware.ts

@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response, NextFunction } from 'express';
import { HTTPError } from '../lib/errors';
export const errorHandler = async (err: HTTPError, req: Request, res: Response, next: NextFunction) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const errorHandler = (err: HTTPError, _req: Request, res: Response, _next: NextFunction) => {
if (err) {
res.status(err.code).json({ code: err.code, message: err.message });
}

8
src/middleware/user.middleware.ts

@ -2,7 +2,7 @@
import { Request, Response, NextFunction } from 'express';
import { getUserById } from '../user/models/user.model';
import { decodeToken } from '../lib/jwt';
import { Unauthorized_Error } from '../lib/errors';
import { UNAUTHORIZED_ERROR } from '../lib/errors';
export const requireAdminOrMod = async (req: Request, res: Response, next: NextFunction) => {
// For sake of example code lets just assume we pull from the http param
@ -11,7 +11,7 @@ export const requireAdminOrMod = async (req: Request, res: Response, next: NextF
if (user?.sitemod || user?.admin) {
next();
} else {
next(Unauthorized_Error);
next(UNAUTHORIZED_ERROR);
}
};
@ -20,13 +20,13 @@ export const requireUserToken = async (req: Request, res: Response, next: NextFu
const token = req.query.auth as string;
if (!token) {
next(Unauthorized_Error);
next(UNAUTHORIZED_ERROR);
}
const payload = await decodeToken(token);
const user = await getUserById(payload.user_id);
if (!user || user.banned) {
next(Unauthorized_Error);
next(UNAUTHORIZED_ERROR);
}
next();
};

2
src/post/post.controller.ts

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response } from 'express';
import { getPostList } from './post.model';

2
src/post/post.model.ts

@ -23,4 +23,4 @@ export interface Post {
featured: boolean;
}
export const getPostList = async (): Promise<Post[]> => await knex<Post>('post');
export const getPostList = async (): Promise<Post[]> => knex<Post>('post');

6
src/private-message/private-message.controller.ts

@ -1,4 +1,8 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response } from 'express';
import { getPrivateMessageList } from './private-message.model';
export const getPrivateMessages = async (req: Request, res: Response) => res.json({ privateMessages: await getPrivateMessageList() });
export const getPrivateMessages = async (req: Request, res: Response) => res.json({
privateMessages: await getPrivateMessageList(),
});

2
src/private-message/private-message.model.ts

@ -13,4 +13,4 @@ export interface PrivateMessage {
local: boolean;
}
export const getPrivateMessageList = async (): Promise<PrivateMessage[]> => await knex<PrivateMessage>('private_message');
export const getPrivateMessageList = async (): Promise<PrivateMessage[]> => knex<PrivateMessage>('private_message');

2
src/site/site.controller.ts

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable import/prefer-default-export */
import { Request, Response } from 'express';
import { getSiteDetail } from './site.model';

2
src/site/site.model.ts

@ -15,4 +15,4 @@ export interface Site {
banner?: string;
}
export const getSiteDetail = async (): Promise<Site|undefined> => await knex<Site>('site').first();
export const getSiteDetail = async (): Promise<Site|undefined> => knex<Site>('site').first();

5
src/user/models/user-ban.model.ts

@ -7,4 +7,7 @@ export interface UserBan {
published: string;
}
export const getUserBan = async (userId: number): Promise<UserBan|undefined> => await knex<UserBan>('user_ban').where('user_id', userId).first();
// eslint-disable-next-line max-len
export const getUserBan = async (userId: number): Promise<UserBan|undefined> => {
return knex<UserBan>('user_ban').where('user_id', userId).first();
};

4
src/user/models/user-mention.model.ts

@ -10,4 +10,6 @@ export interface UserMention {
published: string;
}
export const getUserMentions = async (userId: number): Promise<UserMention[]> => await knex<UserMention>('user_mention').where('recipient_id', userId);
export const getUserMentions = async (userId: number): Promise<UserMention[]> => {
return knex<UserMention>('user_mention').where('recipient_id', userId);
};

4
src/user/models/user-tag.model.ts

@ -10,4 +10,6 @@ export interface UserTag {
tags: UserTags;
}
export const getUserTags = async (userId: number): Promise<UserTag|undefined> => await knex<UserTag>('user_tag').where('user_id', userId).first();
export const getUserTags = async (userId: number): Promise<UserTag|undefined> => {
return knex<UserTag>('user_tag').where('user_id', userId).first();
};

4
src/user/models/user-token.model.ts

@ -11,4 +11,6 @@ export interface UserToken {
is_revoked: boolean;
}
export const getUserTokens = async (userId: number): Promise<UserToken[]> => await knex<UserToken>('hexbear.user_tokens').where('user_id', userId);
export const getUserTokens = async (userId: number): Promise<UserToken[]> => {
return knex<UserToken>('hexbear.user_tokens').where('user_id', userId);
};

14
src/user/models/user.model.ts

@ -1,5 +1,9 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-floating-promises */
import dayjs from 'dayjs';
import { off } from 'process';
import { knex } from '../../database/knex';
import { SortType } from '../../enums';
@ -63,7 +67,13 @@ export interface UserView {
readonly inbox_disabled: User['inbox_disabled'];
}
export const getUserView = async (filter: Partial<User>, omitEmail: boolean = false, sortType?: SortType, limit?: number, offset?: number): Promise<UserView[]> => {
export const getUserView = async (
filter: Partial<User>,
omitEmail = false,
sortType?: SortType,
limit?: number,
offset?: number,
): Promise<UserView[]> => {
const users = await knex<UserView>('hexbear.user_view').modify((query) => {
query.where(filter);

9
src/user/user.controller.ts

@ -14,8 +14,13 @@ router.get('/login', async (req: Request, res: Response) => {
return res.json({ jwt });
});
router.get('/auth-test', requireUserToken, async (req: Request, res: Response) => res.json({ users: await getUserList() }));
router.get('/auth-test', requireUserToken, async (req: Request, res: Response) => res.json({
users: await getUserList(),
}));
router.get('/:userId', requireAdminOrMod, async (req: Request, res: Response) => res.json({ user: await getUserSecure(parseInt(req.params.userId)) }));
router.get('/:userId', requireAdminOrMod, async (req: Request, res: Response) => res.json({
user: await getUserSecure(parseInt(req.params.userId)),
}));
// eslint-disable-next-line import/prefer-default-export
export const UserRoutes = router;
Loading…
Cancel
Save