Skip to content

Commit 599ecc8

Browse files
committed
chore: backend
1 parent 1cf06db commit 599ecc8

6 files changed

Lines changed: 17 additions & 13 deletions

File tree

backend/src/data-source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Otp } from './entities/opt';
55
if (!process.env.DATABASE_URL) {
66
throw new Error('DATABASE_URL is not defined');
77
}
8-
export const appDataSouce = new DataSource({
8+
export const appDataSource = new DataSource({
99
type: 'postgres',
1010
url: process.env.DATABASE_URL,
1111
ssl: {

backend/src/modules/auth/auth.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { logger } from '../../utils/logger';
33
import { emailSchema, registerSchema } from './auth.schema';
44
import { sendOtpEmail } from '../../Services/email.service';
55
import { generateotp } from '../../utils/otp';
6-
import { appDataSouce } from '../../data-source';
6+
import { appDataSource } from '../../data-source';
77
import { Otp } from '../../entities/opt';
88
import { User } from '../../entities/User';
99

@@ -20,7 +20,7 @@ export const sendOtp = async (
2020
.status(400)
2121
.json({ message: 'validation vailed', error: result.error?.format() });
2222
}
23-
const otpRep = appDataSouce.getRepository(Otp);
23+
const otpRep = appDataSource.getRepository(Otp);
2424
const otpcode = generateotp();
2525
logger.debug({ otpcode }, 'otp is');
2626
const email = result.data?.email;
@@ -49,7 +49,7 @@ export const verifyotp = async (
4949
return res.status(400).json({ message: ' otp and email are required' });
5050
}
5151

52-
const otpRepo = appDataSouce.getRepository(Otp);
52+
const otpRepo = appDataSource.getRepository(Otp);
5353
const otpRecord = await otpRepo.findOne({
5454
where: {
5555
email,
@@ -101,8 +101,8 @@ export const register = async (
101101
if (!otpId) {
102102
return res.status(400).json({ message: 'otpid requuired' });
103103
}
104-
const otpRepo = appDataSouce.getRepository(Otp);
105-
const userRepo = appDataSouce.getRepository(User);
104+
const otpRepo = appDataSource.getRepository(Otp);
105+
const userRepo = appDataSource.getRepository(User);
106106

107107
const otpRecord = await otpRepo.findOne({
108108
where: { id: otpId },

backend/src/modules/auth/auth.schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ export const emailSchema = z.object({
33
email: z.string().email('Invalid email'),
44
});
55

6+
export const numberSchema = z.object({
7+
phoneNumber: z.number(),
8+
});
9+
610
export const registerSchema = z.object({
711
otpId: z.string().uuid(),
812
name: z.string().min(1, 'name is required'),

backend/src/modules/health/health.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import express from 'express';
2-
import { appDataSouce } from '../../data-source';
2+
import { appDataSource } from '../../data-source';
33
const Healthrouter = express.Router();
44
Healthrouter.get('/', async (req, res) => {
55
try {
6-
if (!appDataSouce.isInitialized) {
6+
if (!appDataSource.isInitialized) {
77
return res.status(503).json({
88
status: 'eroor',
99
service: 'mysocial-code-backend',
1010
db: 'not initialized',
1111
});
1212
}
13-
await appDataSouce.query('SELECT 1');
13+
await appDataSource.query('SELECT 1');
1414
return res.status(200).json({
1515
status: 'ok',
1616
service: 'mysocial-code-backend',

backend/src/modules/user/user.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NextFunction, Request, Response } from 'express';
22
import { PutObjectCommand } from '@aws-sdk/client-s3';
33
import { r2 } from '../../utils/r2';
4-
import { appDataSouce } from '../../data-source';
4+
import { appDataSource } from '../../data-source';
55
import { User } from '../../entities/User';
66
import { logger } from '../../utils/logger';
77
export const uploadAvatar = async (
@@ -25,7 +25,7 @@ export const uploadAvatar = async (
2525
}),
2626
);
2727
const imageUrl = `${process.env.R2_ENDPOINT}/${process.env.R2_BUCKET_NAME}/${key}`;
28-
const userRepo = appDataSouce.getRepository(User);
28+
const userRepo = appDataSource.getRepository(User);
2929
await userRepo.update(userId, { profileImageUrl: imageUrl });
3030
res
3131
.status(200)

backend/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import dotenv from 'dotenv';
22
dotenv.config();
33
import app from './app';
44
import { logger } from './utils/logger';
5-
import { appDataSouce } from './data-source';
5+
import { appDataSource } from './data-source';
66
if (!process.env.PORT) {
77
throw new Error('PORT is not defined in environment variables');
88
}
99

1010
(async () => {
1111
try {
12-
await appDataSouce.initialize();
12+
await appDataSource.initialize();
1313
logger.info('database connected success fully');
1414
} catch (error) {
1515
logger.error({ err: error }, 'error connecting the database');

0 commit comments

Comments
 (0)