Skip to content

Commit

Permalink
Patch/update node (#459)
Browse files Browse the repository at this point in the history
* update node to 20.12.2

* circleci update

* circleci to cimg

* bump version

* update dependencies

* ts-node upgrade

* typescript 4.4

* dockerfile change

* fix some more

* not working

* best working

* multer lts version

* multer update again

* start typeorm fixes

* remove base entity

* update all to datamapper

* fix tests and factories

* seed works

* event repository

* everything put merch and user handles

* all tests work

* something

* change migration

* migrations in datasource

* migration fixed hopefully

* lint

* fix stuff

* bad typescript

* lockfile

* lint

* typescript and jest, sometimes works, sometimes doesn't

* hopeuflly works

* changed yarn lock

* updated eslint

* faker

* rest of packages

* remove uneeded types package

* eslint small change

* package.json datasource:

* goofy ah

* shuffle stuff

---------

Co-authored-by: = <[email protected]>
  • Loading branch information
maxwn04 and newracket authored Feb 20, 2025
1 parent 5933e49 commit 0b817e3
Show file tree
Hide file tree
Showing 88 changed files with 4,930 additions and 4,684 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
jobs:
build:
docker:
- image: circleci/node:14.17.6
- image: cimg/node:20.12.2
steps:
- checkout
- run:
Expand All @@ -12,7 +12,7 @@ jobs:
command: yarn build
lint:
docker:
- image: circleci/node:14.17.6
- image: cimg/node:20.12.2
steps:
- checkout
- restore_cache:
Expand All @@ -27,7 +27,7 @@ jobs:
command: yarn lint
test:
docker:
- image: circleci/node:14.17.6
- image: cimg/node:20.12.2
environment:
RDS_HOST: localhost
RDS_DATABASE: membership_portal
Expand Down
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

20 changes: 20 additions & 0 deletions DataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Container from 'typedi';
import { DataSource } from 'typeorm';
import { models } from './models';

require('dotenv').config();

export const dataSource = new DataSource({
type: 'postgres',
host: process.env.RDS_HOST,
port: Number(process.env.RDS_PORT),
username: process.env.RDS_USER,
password: process.env.RDS_PASSWORD,
database: process.env.RDS_DATABASE,
entities: models,
migrations: ['migrations/*.ts'],
// synchronize: true, // DO NOT USE IN PRODUCTION, make migrations
});

// important for dependency injection for repositories
Container.set(DataSource, dataSource);
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM node:14.15.3 AS build
FROM node:20.12.2 AS build

WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build

FROM node:14.15.3-alpine
FROM node:20.12.2-alpine
WORKDIR /app
COPY --from=build /app /app
EXPOSE 3000
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/AdminController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JsonController, Post, Patch, UploadedFile, UseBefore, ForbiddenError, Body, Get } from 'routing-controllers';
import { Service } from 'typedi';
import { UserAuthentication } from '../middleware/UserAuthentication';
import {
CreateBonusRequest,
Expand All @@ -25,6 +26,7 @@ import { UserModel } from '../../models/UserModel';
import AttendanceService from '../../services/AttendanceService';

@UseBefore(UserAuthentication)
@Service()
@JsonController('/admin')
export class AdminController {
private storageService: StorageService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/AttendanceController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JsonController, Get, Post, UseBefore, Params, ForbiddenError, Body } from 'routing-controllers';
import { Service } from 'typedi';
import EmailService from '../../services/EmailService';
import { UserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
Expand All @@ -9,6 +10,7 @@ import PermissionsService from '../../services/PermissionsService';
import { GetAttendancesForEventResponse, GetAttendancesForUserResponse, AttendEventResponse } from '../../types';
import { UuidParam } from '../validators/GenericRequests';

@Service()
@JsonController('/attendance')
export class AttendanceController {
private attendanceService: AttendanceService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/AuthController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JsonController, Params, Body, Get, Post, UseBefore } from 'routing-controllers';
import { Service } from 'typedi';
import {
RegistrationResponse,
LoginResponse,
Expand Down Expand Up @@ -26,6 +27,7 @@ import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import { EmailParam, AccessCodeParam } from '../validators/GenericRequests';

@Service()
@JsonController('/auth')
export class AuthController {
private userAccountService: UserAccountService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/EventController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
JsonController, Get, Patch, Delete, Post, UseBefore, Params, ForbiddenError, QueryParams, UploadedFile, Body,
} from 'routing-controllers';
import { Service } from 'typedi';
import EventService from '../../services/EventService';
import { UserAuthentication, OptionalUserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
Expand Down Expand Up @@ -28,6 +29,7 @@ import {
SubmitEventFeedbackRequest,
} from '../validators/EventControllerRequests';

@Service()
@JsonController('/event')
export class EventController {
private eventService: EventService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/FeedbackController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Body, ForbiddenError, Get, JsonController, Params,
Patch, Post, UseBefore, QueryParams } from 'routing-controllers';
import { Service } from 'typedi';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import PermissionsService from '../../services/PermissionsService';
Expand All @@ -14,6 +15,7 @@ import {
} from '../validators/FeedbackControllerRequests';

@UseBefore(UserAuthentication)
@Service()
@JsonController('/feedback')
export class FeedbackController {
private feedbackService: FeedbackService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/LeaderboardController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { UseBefore, JsonController, Get, QueryParams } from 'routing-controllers';
import { Service } from 'typedi';
import { GetLeaderboardResponse } from '../../types';
import { UserAuthentication } from '../middleware/UserAuthentication';
import UserAccountService from '../../services/UserAccountService';
import { SlidingLeaderboardQueryParams } from '../validators/LeaderboardControllerRequests';

@UseBefore(UserAuthentication)
@Service()
@JsonController('/leaderboard')
export class LeaderboardController {
private userAccountService: UserAccountService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/MerchStoreController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UploadedFile,
} from 'routing-controllers';
import { v4 as uuid } from 'uuid';
import { Service } from 'typedi';
import PermissionsService from '../../services/PermissionsService';
import { UserAuthentication } from '../middleware/UserAuthentication';
import {
Expand Down Expand Up @@ -76,6 +77,7 @@ import { UserError } from '../../utils/Errors';
import StorageService from '../../services/StorageService';

@UseBefore(UserAuthentication)
@Service()
@JsonController('/merch')
export class MerchStoreController {
private merchStoreService: MerchStoreService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/ResumeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Delete,
} from 'routing-controllers';
import * as path from 'path';
import { Service } from 'typedi';
import PermissionsService from '../../services/PermissionsService';
import StorageService from '../../services/StorageService';
import { UserAuthentication } from '../middleware/UserAuthentication';
Expand All @@ -24,6 +25,7 @@ import { PatchResumeRequest, UploadResumeRequest } from '../validators/ResumeCon
import { UuidParam } from '../validators/GenericRequests';

@UseBefore(UserAuthentication)
@Service()
@JsonController('/resume')
export class ResumeController {
private resumeService: ResumeService;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/UserController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
JsonController, Params, Get, Post, Patch, UseBefore, UploadedFile, Body, Delete,
} from 'routing-controllers';
import { Service } from 'typedi';
import { UserModel } from '../../models/UserModel';
import UserAccountService from '../../services/UserAccountService';
import UserSocialMediaService from '../../services/UserSocialMediaService';
Expand All @@ -27,6 +28,7 @@ import {
} from '../validators/UserSocialMediaControllerRequests';

@UseBefore(UserAuthentication)
@Service()
@JsonController('/user')
export class UserController {
private userAccountService: UserAccountService;
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { UserModel } from '../../models/UserModel';
import { UserController } from './UserController';
import { AuthController } from './AuthController';
Expand Down
2 changes: 2 additions & 0 deletions api/middleware/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as express from 'express';
import { ExpressErrorMiddlewareInterface, Middleware } from 'routing-controllers';
import { Service } from 'typedi';
import { handleError } from '../../error';

@Service()
@Middleware({ type: 'after' })
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
error(error: Error, request: express.Request, response: express.Response, next: (err?: any) => any): void {
Expand Down
2 changes: 2 additions & 0 deletions api/middleware/MetricsRecorder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';
import * as express from 'express';
import * as metrics from 'datadog-metrics';
import { Service } from 'typedi';

@Service()
@Middleware({ type: 'after', priority: 1 })
export class MetricsRecorder implements ExpressMiddlewareInterface {
async use(request: express.Request, response: express.Response, next?: express.NextFunction) {
Expand Down
2 changes: 2 additions & 0 deletions api/middleware/NotFoundHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ExpressMiddlewareInterface, NotFoundError, Middleware } from 'routing-controllers';
import * as express from 'express';
import { Service } from 'typedi';
import { handleError } from '../../error';

@Service()
@Middleware({ type: 'after' })
export class NotFoundHandler implements ExpressMiddlewareInterface {
use(request: express.Request, response: express.Response, next: express.NextFunction) {
Expand Down
2 changes: 2 additions & 0 deletions api/middleware/RequestLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import * as crypto from 'crypto';
import * as express from 'express';
import * as moment from 'moment';
import * as morgan from 'morgan';
import { Service } from 'typedi';

@Service()
@Middleware({ type: 'before' })
export class RequestLogger implements ExpressMiddlewareInterface {
async use(request: express.Request, response: express.Response, next?: express.NextFunction) {
Expand Down
5 changes: 3 additions & 2 deletions api/middleware/UserAuthentication.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ExpressMiddlewareInterface, ForbiddenError } from 'routing-controllers';
import * as express from 'express';
import { Inject } from 'typedi';
import { Inject, Service } from 'typedi';
import UserAuthService from '../../services/UserAuthService';
import { authActionMetadata } from '../../utils/AuthActionMetadata';
import { logger as log } from '../../utils/Logger';

@Service()
export class UserAuthentication implements ExpressMiddlewareInterface {
@Inject()
private userAuthService: UserAuthService;
Expand All @@ -28,7 +29,7 @@ export class OptionalUserAuthentication implements ExpressMiddlewareInterface {
request.user = await this.userAuthService.checkAuthToken(authHeader);
log.info('user authentication (middleware)', authActionMetadata(request.trace, request.user));
} catch (error) {
log.debug('optional user auth (middleware)');
log.debug(`optional user auth (middleware): ${error}`);
}
return next();
}
Expand Down
2 changes: 1 addition & 1 deletion config/DatabaseNamingStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DefaultNamingStrategy, NamingStrategyInterface, Table } from 'typeorm';

export class DatabaseNamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
private getTableName(tableOrName: string | Table) {
protected getTableName(tableOrName: string | Table) {
const tableName = typeof tableOrName === 'string' ? tableOrName : tableOrName.name;
return tableName;
}
Expand Down
68 changes: 68 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const eslintParser = require('@typescript-eslint/parser');

module.exports = [
{
// Apply to all files
files: ['**/*.ts', '**/*.tsx'],
ignores: ['node_modules/**', 'build/**', 'logs/**', '.env'],
languageOptions: {
parser: eslintParser,
parserOptions: {
project: './tsconfig.json',
ecmaVersion: 2020,
sourceType: 'module',
},
globals: {
browser: true,
node: true,
jest: true,
},
},
plugins: {
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
},
rules: {
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: 'type|_*',
},
],
'class-methods-use-this': 'off',
'consistent-return': 'off',
'func-names': 'off',
'global-require': 'off',
'import/no-cycle': 'off',
'import/prefer-default-export': 'off',
'max-classes-per-file': 'off',
'max-len': [
'error',
{
code: 120,
},
],
'no-bitwise': [
'error',
{
allow: ['^'],
},
],
'no-param-reassign': 'off',
'no-unused-vars': 'off',
'object-curly-newline': [
'error',
{
consistent: true,
},
],
},
},
{
// Specific rules for test files
files: ['tests/*.test.ts'],
rules: {
'no-await-in-loop': 'off',
},
},
];
42 changes: 12 additions & 30 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
import 'reflect-metadata'; // this shim is required

import { createExpressServer, useContainer as routingUseContainer } from 'routing-controllers';

import { createConnection, useContainer as ormUseContainer } from 'typeorm';
import { Container } from 'typedi';
import { models as entities } from './models';

import Container from 'typedi';
import { createExpressServer, useContainer } from 'routing-controllers';
import { dataSource } from './DataSource';
import { Config } from './config';
import { InMemoryDatabaseCache } from './utils/InMemoryDatabaseCache';
import { logger as log } from './utils/Logger';
import { controllers } from './api/controllers';
import { middlewares } from './api/middleware';

routingUseContainer(Container);
ormUseContainer(Container);
dataSource
.initialize()
.then(() => {
console.log('created connection');
})
.catch((error) => {
console.log(error);
});

createConnection({
type: 'postgres',
host: Config.database.host,
port: Config.database.port,
username: Config.database.user,
password: Config.database.pass,
database: Config.database.name,
entities,
logging: Config.isDevelopment,
cache: {
provider(_connection) {
return new InMemoryDatabaseCache();
},
},
}).then(() => {
log.info('created connection');
}).catch((error) => {
log.error(error);
});
useContainer(Container);

const app = createExpressServer({
cors: true,
Expand Down
Loading

0 comments on commit 0b817e3

Please sign in to comment.