Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Node Version to 20.12.2 #435

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d69fea5
update node to 20.12.2
maxwn04 Apr 13, 2024
95a790a
circleci update
maxwn04 Apr 13, 2024
3f0ffc4
circleci to cimg
maxwn04 Apr 13, 2024
26b7aae
bump version
maxwn04 Apr 13, 2024
24036a0
update dependencies
maxwn04 Apr 17, 2024
2cffa6a
ts-node upgrade
maxwn04 Apr 17, 2024
378cbff
typescript 4.4
maxwn04 Apr 19, 2024
cf16c91
dockerfile change
maxwn04 Apr 23, 2024
2367817
fix some more
maxwn04 Apr 24, 2024
eb7bb65
not working
maxwn04 Apr 29, 2024
d6ba260
best working
maxwn04 Apr 29, 2024
de6b1d2
Merge branch 'patch/update-node' of https://github.com/acmucsd/member…
maxwn04 Apr 29, 2024
9196f7f
multer lts version
maxwn04 Apr 29, 2024
d79a02f
multer update again
maxwn04 Apr 29, 2024
c4c4d89
Merge branch 'master' into patch/update-node
maxwn04 Nov 26, 2024
0715226
start typeorm fixes
maxwn04 Dec 1, 2024
a7eb386
remove base entity
maxwn04 Dec 18, 2024
75f81a4
update all to datamapper
maxwn04 Dec 25, 2024
a40ac92
fix tests and factories
maxwn04 Dec 28, 2024
cc92b91
seed works
maxwn04 Dec 28, 2024
4873fa3
event repository
maxwn04 Dec 30, 2024
2d633e0
everything put merch and user handles
maxwn04 Dec 30, 2024
b449b86
all tests work
maxwn04 Dec 31, 2024
aa27f9b
something
maxwn04 Dec 31, 2024
82bedbc
change migration
maxwn04 Dec 31, 2024
617198f
migrations in datasource
maxwn04 Dec 31, 2024
946856b
migration fixed hopefully
maxwn04 Dec 31, 2024
757ea5c
lint
maxwn04 Dec 31, 2024
493ffce
fix stuff
maxwn04 Jan 9, 2025
0d2dcd5
bad typescript
maxwn04 Jan 9, 2025
7e36ffe
lockfile
maxwn04 Jan 9, 2025
4664b1b
lint
maxwn04 Jan 9, 2025
a883272
typescript and jest, sometimes works, sometimes doesn't
maxwn04 Jan 9, 2025
185674e
hopeuflly works
maxwn04 Jan 10, 2025
78cca2b
changed yarn lock
newracket Jan 10, 2025
34b77ff
updated eslint
newracket Jan 10, 2025
840ad5e
faker
maxwn04 Jan 17, 2025
d5eb9a5
rest of packages
maxwn04 Jan 17, 2025
28bc350
remove uneeded types package
maxwn04 Jan 17, 2025
2cf4d9c
eslint small change
maxwn04 Jan 23, 2025
01317c3
package.json datasource:
maxwn04 Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading