Skip to content

Commit

Permalink
Merge pull request #25 from get-amigo/staging
Browse files Browse the repository at this point in the history
Deploy group create bug fix and group invite flow to prod
  • Loading branch information
tirthajyoti-ghosh authored Aug 18, 2024
2 parents 8c7894f + 716d0ba commit ec996eb
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 170 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
echo "JWT_SECRET=\"${{ secrets.DEV_JWT_SECRET }}\"" >> .env
echo "DATABASE_URL=\"${{ secrets.DEV_DATABASE_URL }}\"" >> .env
echo "CRYPTO_SECRET_KEY=\"${{ secrets.DEV_CRYPTO_SECRET_KEY }}\"" >> .env
echo "ACCESS_CODE_EXPIRY=\"1y\"" >> .env
echo "ENV=\"development\"" >> .env
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
echo "JWT_SECRET=\"${{ secrets.PRODUCTION_JWT_SECRET }}\"" >> .env
echo "DATABASE_URL=\"${{ secrets.PRODUCTION_DATABASE_URL }}\"" >> .env
echo "CRYPTO_SECRET_KEY=\"${{ secrets.PRODUCTION_CRYPTO_SECRET_KEY }}\"" >> .env
echo "FIREBASE_WEB_API_KEY=\"${{ secrets.FIREBASE_WEB_API_KEY }}\"" >> .env
echo "FIREBASE_PROJECT_ID=\"${{ secrets.FIREBASE_PROJECT_ID }}\"" >> .env
echo "FIREBASE_CLIENT_EMAIL=\"${{ secrets.FIREBASE_CLIENT_EMAIL }}\"" >> .env
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
echo "JWT_SECRET=\"${{ secrets.STAGING_JWT_SECRET }}\"" >> .env
echo "DATABASE_URL=\"${{ secrets.STAGING_DATABASE_URL }}\"" >> .env
echo "CRYPTO_SECRET_KEY=\"${{ secrets.STAGING_CRYPTO_SECRET_KEY }}\"" >> .env
echo "FIREBASE_WEB_API_KEY=\"${{ secrets.FIREBASE_WEB_API_KEY }}\"" >> .env
echo "FIREBASE_PROJECT_ID=\"${{ secrets.FIREBASE_PROJECT_ID }}\"" >> .env
echo "FIREBASE_CLIENT_EMAIL=\"${{ secrets.FIREBASE_CLIENT_EMAIL }}\"" >> .env
Expand Down
122 changes: 18 additions & 104 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"bcrypt": "^5.1.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"cryptojs": "^2.5.3",
"firebase-admin": "^12.1.0",
"mern-task-backend": "file:",
"mongoose": "^8.0.3",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.2.1",
"rxjs": "^7.8.1",
"twilio": "^4.20.0"
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.3.0",
Expand Down
7 changes: 2 additions & 5 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ JWT_SECRET=
PORT=3000
DATABASE_URL=mongodb+srv://
ACCESS_CODE_EXPIRY=1y
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_VERIFICATION_SID=
TWILIO_PHONE_NUMBER=
ENV=development
ENV=development
CRYPTO_SECRET_KEY=(32 digit hex)
37 changes: 0 additions & 37 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { JwtService } from '@nestjs/jwt';
import { UsersService } from 'src/users/users.service';
import * as bcrypt from 'bcrypt';
import { generalError } from 'src/utils/generalError';
import Twilio from 'twilio';
import getCountryCodeAndPhoneNumber from 'src/utils/getCountryCodeAndPhoneNumber';
import { verifyToken } from 'src/utils/firebase';

Expand Down Expand Up @@ -89,42 +88,6 @@ export class AuthService {
}
}

async verifyOTPAndEditPhoneNumber(userId, otpBody, response) {
const { phoneNumber, countryCode, otp } = otpBody;

if (process.env.ENV === 'production') {
await this.verifyTwilioOTP(phoneNumber, countryCode, otp, response);
}

const newUser = await this.userService.editUser(userId, {
phoneNumber,
countryCode,
});
response.json(newUser);
}

async verifyTwilioOTP(phoneNumber, countryCode, otp, response) {
const client = Twilio(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_AUTH_TOKEN,
);

const verificationToken = process.env.TWILIO_VERIFICATION_SID;

const verificationCheck = await client.verify.v2
.services(verificationToken)
.verificationChecks.create({
to: `+${countryCode}${phoneNumber}`,
code: otp,
});

const { status } = verificationCheck;

if (status !== 'approved') {
return response.json({ status });
}
}

async verifyUser(login) {
const user = await this.userService.findByEmail(login.email);
if (!user) {
Expand Down
9 changes: 7 additions & 2 deletions src/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export class GroupController {
}

@Post(':id/join')
joinGroup(@Req() req: Request, @Param('id') groupId) {
joinGroup(@Req() req: Request, @Param('id') hashedGroupId) {
const { id } = req['user'];
return this.groupService.joinGroup(groupId, new Types.ObjectId(id));
return this.groupService.joinGroup(hashedGroupId, new Types.ObjectId(id));
}

@Post(':id/chat')
Expand All @@ -77,4 +77,9 @@ export class GroupController {
getAllTransactions(@Param('id') groupId) {
return this.groupService.getAllTransactions(groupId);
}

@Get(':id/token')
async getGroupToken(@Param('id') groupId){
return this.groupService.generateToken(groupId);
}
}
13 changes: 13 additions & 0 deletions src/group/group.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { ChatService } from 'src/chat/chat.service';
import { ChatModule } from 'src/chat/chat.module';
import ChatSchema from 'src/chat/chat.schema';
import GroupBalanceSchema from 'src/balance/groupBalance.schema';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
TransactionModule,
Expand All @@ -34,7 +36,18 @@ import GroupBalanceSchema from 'src/balance/groupBalance.schema';
ChatSchema,
GroupBalanceSchema,
]),

JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => {
return {
secret: config.get<string>('JWT_SECRET'),
};
},
inject: [ConfigService],
}),
],

controllers: [GroupController, UsersController],
providers: [
GroupService,
Expand Down
Loading

0 comments on commit ec996eb

Please sign in to comment.