Skip to content

Commit 54d6b0c

Browse files
committed
format file with prettier rules
1 parent bcdfb9a commit 54d6b0c

File tree

42 files changed

+541
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+541
-250
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"semi": true,
44
"trailingComma": "all",
55
"singleQuote": true,
6-
"printWidth": 100,
6+
"printWidth": 80,
77
"tabWidth": 2
88
}

.templates/database/model/Sample.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ const schema = new Schema<Sample>(
4343
},
4444
);
4545

46-
export const SampleModel = model<Sample>(DOCUMENT_NAME, schema, COLLECTION_NAME);
46+
export const SampleModel = model<Sample>(
47+
DOCUMENT_NAME,
48+
schema,
49+
COLLECTION_NAME,
50+
);

.templates/database/repository/SampleRepo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ async function create(sample: Sample): Promise<Sample> {
1515

1616
async function update(sample: Sample): Promise<Sample | null> {
1717
sample.updatedAt = new Date();
18-
return SampleModel.findByIdAndUpdate(sample._id, sample, { new: true }).lean().exec();
18+
return SampleModel.findByIdAndUpdate(sample._id, sample, { new: true })
19+
.lean()
20+
.exec();
1921
}
2022

2123
export default {

addons/init-mongo.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,30 @@ function seed(dbName, user, password) {
2020
});
2121

2222
db.roles.insertMany([
23-
{ code: 'LEARNER', status: true, createdAt: new Date(), updatedAt: new Date() },
24-
{ code: 'WRITER', status: true, createdAt: new Date(), updatedAt: new Date() },
25-
{ code: 'EDITOR', status: true, createdAt: new Date(), updatedAt: new Date() },
26-
{ code: 'ADMIN', status: true, createdAt: new Date(), updatedAt: new Date() },
23+
{
24+
code: 'LEARNER',
25+
status: true,
26+
createdAt: new Date(),
27+
updatedAt: new Date(),
28+
},
29+
{
30+
code: 'WRITER',
31+
status: true,
32+
createdAt: new Date(),
33+
updatedAt: new Date(),
34+
},
35+
{
36+
code: 'EDITOR',
37+
status: true,
38+
createdAt: new Date(),
39+
updatedAt: new Date(),
40+
},
41+
{
42+
code: 'ADMIN',
43+
status: true,
44+
createdAt: new Date(),
45+
updatedAt: new Date(),
46+
},
2747
]);
2848

2949
db.users.insert({

src/app.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import cors from 'cors';
44
import { corsUrl, environment } from './config';
55
import './database'; // initialize database
66
import './cache'; // initialize cache
7-
import { NotFoundError, ApiError, InternalError, ErrorType } from './core/ApiError';
7+
import {
8+
NotFoundError,
9+
ApiError,
10+
InternalError,
11+
ErrorType,
12+
} from './core/ApiError';
813
import routesV1 from './routes/v1';
914

1015
process.on('uncaughtException', (e) => {
@@ -14,7 +19,9 @@ process.on('uncaughtException', (e) => {
1419
const app = express();
1520

1621
app.use(express.json({ limit: '10mb' }));
17-
app.use(express.urlencoded({ limit: '10mb', extended: true, parameterLimit: 50000 }));
22+
app.use(
23+
express.urlencoded({ limit: '10mb', extended: true, parameterLimit: 50000 }),
24+
);
1825
app.use(cors({ origin: corsUrl, optionsSuccessStatus: 200 }));
1926

2027
// Routes
@@ -29,9 +36,13 @@ app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
2936
if (err instanceof ApiError) {
3037
ApiError.handle(err, res);
3138
if (err.type === ErrorType.INTERNAL)
32-
Logger.error(`500 - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`);
39+
Logger.error(
40+
`500 - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`,
41+
);
3342
} else {
34-
Logger.error(`500 - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`);
43+
Logger.error(
44+
`500 - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`,
45+
);
3546
Logger.error(err);
3647
if (environment === 'development') {
3748
return res.status(500).send(err);

src/auth/authUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { tokenInfo } from '../config';
77

88
export const getAccessToken = (authorization?: string) => {
99
if (!authorization) throw new AuthFailureError('Invalid Authorization');
10-
if (!authorization.startsWith('Bearer ')) throw new AuthFailureError('Invalid Authorization');
10+
if (!authorization.startsWith('Bearer '))
11+
throw new AuthFailureError('Invalid Authorization');
1112
return authorization.split(' ')[1];
1213
};
1314

src/auth/authentication.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import express from 'express';
22
import { ProtectedRequest } from 'app-request';
33
import UserRepo from '../database/repository/UserRepo';
4-
import { AuthFailureError, AccessTokenError, TokenExpiredError } from '../core/ApiError';
4+
import {
5+
AuthFailureError,
6+
AccessTokenError,
7+
TokenExpiredError,
8+
} from '../core/ApiError';
59
import JWT from '../core/JWT';
610
import KeystoreRepo from '../database/repository/KeystoreRepo';
711
import { Types } from 'mongoose';

src/cache/query.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export async function addToList(key: Key | DynamicKeyType, value: any) {
7272
return await cache.rPushX(key, item);
7373
}
7474

75-
export async function getListRange<T>(key: Key | DynamicKeyType, start = 0, end = -1) {
75+
export async function getListRange<T>(
76+
key: Key | DynamicKeyType,
77+
start = 0,
78+
end = -1,
79+
) {
7680
const type = await cache.type(key);
7781
if (type !== TYPES.LIST) return null;
7882

@@ -98,7 +102,10 @@ export async function setOrderedSet(
98102
return await multi.exec();
99103
}
100104

101-
export async function addToOrderedSet(key: Key, items: Array<{ score: number; value: any }>) {
105+
export async function addToOrderedSet(
106+
key: Key,
107+
items: Array<{ score: number; value: any }>,
108+
) {
102109
const type = await cache.type(key);
103110
if (type !== TYPES.ZSET) return null;
104111

src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ export const redis = {
3131
};
3232

3333
export const caching = {
34-
contentCacheDuration: parseInt(process.env.CONTENT_CACHE_DURATION_MILLIS || '600000'),
35-
};
34+
contentCacheDuration: parseInt(
35+
process.env.CONTENT_CACHE_DURATION_MILLIS || '600000',
36+
),
37+
};

src/core/ApiResponse.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ abstract class ApiResponse {
3333
return res.status(this.status).json(ApiResponse.sanitize(response));
3434
}
3535

36-
public send(res: Response, headers: { [key: string]: string } = {}): Response {
36+
public send(
37+
res: Response,
38+
headers: { [key: string]: string } = {},
39+
): Response {
3740
return this.prepare<ApiResponse>(res, this, headers);
3841
}
3942

@@ -107,7 +110,11 @@ export class AccessTokenErrorResponse extends ApiResponse {
107110
private instruction = 'refresh_token';
108111

109112
constructor(message = 'Access token invalid') {
110-
super(StatusCode.INVALID_ACCESS_TOKEN, ResponseStatus.UNAUTHORIZED, message);
113+
super(
114+
StatusCode.INVALID_ACCESS_TOKEN,
115+
ResponseStatus.UNAUTHORIZED,
116+
message,
117+
);
111118
}
112119

113120
send(res: Response, headers: { [key: string]: string } = {}): Response {
@@ -117,7 +124,11 @@ export class AccessTokenErrorResponse extends ApiResponse {
117124
}
118125

119126
export class TokenRefreshResponse extends ApiResponse {
120-
constructor(message: string, private accessToken: string, private refreshToken: string) {
127+
constructor(
128+
message: string,
129+
private accessToken: string,
130+
private refreshToken: string,
131+
) {
121132
super(StatusCode.SUCCESS, ResponseStatus.SUCCESS, message);
122133
}
123134

0 commit comments

Comments
 (0)