Skip to content

Commit cdc90cd

Browse files
committed
fix: update deps and structure
1 parent 4543e64 commit cdc90cd

26 files changed

+709
-367
lines changed

app/app.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import helmet from 'helmet'
44
import logger from 'morgan'
55

66
import { env } from './config'
7-
import {
8-
globalErrorHandler,
9-
globalLimiter,
10-
notFoundHandler
11-
} from './middlewares'
7+
import { globalErrorHandler, notFoundHandler } from './middlewares'
128
import { apiRouter } from './routes'
139

1410
export const app = express()
1511

1612
app.use(helmet())
1713
app.use(cors({ origin: env.ALLOWED_ORIGINS }))
18-
app.use(globalLimiter)
1914
app.use(logger(app.get('env') === 'development' ? 'dev' : 'combined'))
2015
app.use(express.json())
2116

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Theme } from '@prisma/client'
2+
3+
export const defaultUserAvatars: Record<Theme, string> = {
4+
light:
5+
'https://res.cloudinary.com/dmbnnewoy/image/upload/v1706958682/TaskPro/user_avatar_default/user_light.png',
6+
dark: 'https://res.cloudinary.com/dmbnnewoy/image/upload/v1706958682/TaskPro/user_avatar_default/user_dark.png',
7+
violet:
8+
'https://res.cloudinary.com/dmbnnewoy/image/upload/v1706958682/TaskPro/user_avatar_default/user_violet.png'
9+
}

app/config/env.config.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,28 @@ const envSchema = z.object({
1111
DATABASE_URL: z.string(),
1212
GOOGLE_CLIENT_ID: z.string(),
1313
GOOGLE_CLIENT_SECRET: z.string(),
14-
GOOGLE_REDIRECT_URI: z.string().url(),
14+
GOOGLE_REDIRECT_URI: z.url(),
1515
REDIS_USERNAME: z.string(),
1616
REDIS_PASSWORD: z.string(),
1717
REDIS_HOST: z.string(),
18-
REDIS_PORT: z.preprocess(
19-
v => (v ? v : undefined),
20-
z.coerce.number().int().positive()
21-
),
18+
REDIS_PORT: z.coerce.number().int().positive().min(1000).max(65535),
2219
ACCESS_JWT_SECRET: z.string().transform(v => new TextEncoder().encode(v)),
2320
REFRESH_JWT_SECRET: z.string().transform(v => new TextEncoder().encode(v)),
24-
PORT: z.preprocess(
25-
v => (v ? v : undefined),
26-
z.coerce.number().int().positive()
27-
),
21+
PORT: z.coerce.number().int().positive().min(1000).max(65535),
2822
API_PREFIX: z.string(),
2923
ALLOWED_ORIGINS: z
3024
.string()
3125
.transform(v => v.split(','))
32-
.pipe(z.array(z.string().url())),
26+
.pipe(z.array(z.url())),
3327
EMAIL_HOST: z.string(),
34-
EMAIL_PORT: z
35-
.number({ coerce: true })
36-
.refine(v => availableEmailPorts.includes(v), {
37-
message: `Email port must be one of the following: ${availableEmailPorts.join(', ')}`
38-
}),
39-
EMAIL_USER: z.string().email(),
40-
EMAIL_RECEIVER: z.string().email(),
28+
EMAIL_PORT: z.coerce
29+
.number()
30+
.refine(
31+
v => availableEmailPorts.includes(v),
32+
`Email port must be one of the following: ${availableEmailPorts.join(', ')}`
33+
),
34+
EMAIL_USER: z.email(),
35+
EMAIL_RECEIVER: z.email(),
4136
EMAIL_PASSWORD: z.string(),
4237
ACCESS_JWT_EXPIRES_IN: z.string(),
4338
REFRESH_JWT_EXPIRES_IN: z.string(),

app/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { transport } from './mailer.config'
22
export { default } from './cloudinary.config'
33
export { env } from './env.config'
44
export { redisClient } from './redis.config'
5+
export { defaultUserAvatars } from './default-user-avatars.config'

app/controllers/auth.controller.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import type {
55
SigninSchema,
66
SignupSchema
77
} from '@/schemas'
8-
import type { JwtPayload } from '@/types'
8+
import type { JwtPayload, TypedRequestBody } from '@/types'
99
import type { NextFunction, Request, Response } from 'express'
10-
import type { TypedRequestBody } from 'zod-express-middleware'
1110

1211
import { prisma } from '@/prisma'
1312
import { hash, verify } from 'argon2'
@@ -16,7 +15,7 @@ import { Conflict, Forbidden, Unauthorized } from 'http-errors'
1615
import { jwtVerify, SignJWT } from 'jose'
1716
import { JWTExpired } from 'jose/errors'
1817

19-
import { env, redisClient } from '@/config'
18+
import { defaultUserAvatars, env, redisClient } from '@/config'
2019

2120
const {
2221
ACCESS_JWT_EXPIRES_IN,
@@ -31,7 +30,7 @@ const {
3130
} = env
3231

3332
class AuthController {
34-
googleClient = new OAuth2Client(
33+
private googleClient = new OAuth2Client(
3534
GOOGLE_CLIENT_ID,
3635
GOOGLE_CLIENT_SECRET,
3736
GOOGLE_REDIRECT_URI
@@ -133,11 +132,15 @@ class AuthController {
133132

134133
const payload = ticket.getPayload()
135134

136-
if (!payload || !payload.email || !payload.name || !payload.picture) {
135+
if (!payload || !payload.email) {
137136
return next(Forbidden('Invalid token'))
138137
}
139138

140-
const { name, email, picture } = payload
139+
const {
140+
email,
141+
name = 'Guest',
142+
picture = defaultUserAvatars.light
143+
} = payload
141144

142145
const user = await prisma.user.findUnique({
143146
where: { email }

app/controllers/board.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import type {
33
BoardParamsSchema,
44
EditBoardSchema
55
} from '@/schemas'
6-
import type { NextFunction, Request, Response } from 'express'
7-
import type { ZodType } from 'zod'
86
import type {
97
TypedRequest,
108
TypedRequestBody,
119
TypedRequestParams
12-
} from 'zod-express-middleware'
10+
} from '@/types'
11+
import type { NextFunction, Request, Response } from 'express'
12+
import type { ZodType } from 'zod'
1313

1414
import { prisma } from '@/prisma'
1515
import { NotFound } from 'http-errors'

app/controllers/card.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type {
55
EditCardSchema,
66
UpdateCardOrderSchema
77
} from '@/schemas'
8+
import type { TypedRequest, TypedRequestParams } from '@/types'
89
import type { NextFunction, Response } from 'express'
910
import type { ZodType } from 'zod'
10-
import type { TypedRequest, TypedRequestParams } from 'zod-express-middleware'
1111

1212
import { prisma } from '@/prisma'
1313
import { BadRequest, NotFound } from 'http-errors'

app/controllers/column.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type {
55
EditColumnSchema,
66
UpdateColumnOrderSchema
77
} from '@/schemas'
8+
import type { TypedRequest, TypedRequestParams } from '@/types'
89
import type { NextFunction, Response } from 'express'
910
import type { ZodType } from 'zod'
10-
import type { TypedRequest, TypedRequestParams } from 'zod-express-middleware'
1111

1212
import { prisma } from '@/prisma'
1313
import { BadRequest, NotFound } from 'http-errors'

app/controllers/user.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { EditUserSchema, NeedHelpSchema } from '@/schemas'
2+
import type { TypedRequestBody } from '@/types'
23
import type { User } from '@prisma/client'
34
import type { NextFunction, Request, Response } from 'express'
45
import type { Options } from 'nodemailer/lib/mailer'
5-
import type { TypedRequestBody } from 'zod-express-middleware'
66

77
import { prisma } from '@/prisma'
88
import { hash } from 'argon2'

app/middlewares/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { authenticate } from './authenticate'
22
export { upload } from './multer'
3-
export { globalLimiter } from './limiter'
3+
export { validateRequest } from './validate-request'
44
export { notFoundHandler, globalErrorHandler } from './errorHandler'

0 commit comments

Comments
 (0)