Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…awa-api into recurring-events-query
  • Loading branch information
meetulr committed Feb 18, 2024
2 parents 0061f63 + 3cf57a0 commit 605b47f
Show file tree
Hide file tree
Showing 10 changed files with 600 additions and 109 deletions.
38 changes: 37 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ jobs:
MONGO_DB_URL: mongodb://localhost:27017/talawa-test-db
REDIS_HOST: localhost
REDIS_PORT: 6379
RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}}
RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}}
MAIL_USERNAME: ${{secrets.MAIL_USERNAME}}
MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
IS_SMTP: ""
SMTP_HOST: ""
SMTP_PASSWORD: ""
SMTP_USERNAME: ""
LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com"
COLORIZE_LOGS: "true"
LOG_LEVEL: "info"
# ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
# REFRESH_TOKEN_SECRET: ${{ secrets.REFRESH_TOKEN_SECRET }}

steps:
- name: Checkout repository
Expand All @@ -153,6 +166,29 @@ jobs:

- name: Run the tests
run: npm run test

- name: Start the development server
run: |
npm run dev &
echo "Development server started..."
- name: Check server status
run: |
if curl -f 'http://localhost:4000' | jq -e '. == {"talawa-version":"v1","status":"healthy"}' > /dev/null; then
echo "Server is up and healthy"
else
echo "Server is down"
exit 1
fi
- name: Check Apollo Server status
run: |
if curl -f 'http://localhost:4000/graphql?query=%7B__typename%7D' \
-H 'Apollo-Require-Preflight: true' | jq -e '. == {"data":{"__typename":"Query"}}' > /dev/null; then
echo "Apollo Server is up"
else
echo "Server is down"
exit 1
fi
- name: Import Sample Data
run: npm run import:sample-data
Expand All @@ -170,7 +206,7 @@ jobs:
with:
path: './coverage/lcov.info'
min_coverage: 95.0

JSDocs:
name: 'JSDocs comments and pipeline'
runs-on: ubuntu-latest
Expand Down
60 changes: 40 additions & 20 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ jobs:
Generate-Documentation:
name: Generate Documentation
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/automated-docs'
needs: Push-Workflow
steps:
- name: Checkout repository
uses: actions/checkout@v3

# with:
# persist-credentials: false
- name: Generate Documentation of HTML pages
run: |
npm install --global typedoc
Expand Down Expand Up @@ -142,31 +143,50 @@ jobs:
git push -f https://$GH_TOKEN@github.com/PalisadoesFoundation/talawa-api.git HEAD:automated-docs
echo -e "🚀${Green} Hurrah! doc updated${NoColor}"
env:
ACCESS_TOKEN: ${{ secrets.GH_TOKEN }}
ACCESS_TOKEN: ${{secrets.GH_TOKEN}}

- name: Create Documentation Artifact
uses: actions/upload-artifact@v2
with:
name: documentation-api
path: talawa-api-docs

Empty-Commit:
name: Create Empty Commit
runs-on: ubuntu-latest
needs: Generate-Documentation
if: github.ref == 'refs/heads/develop'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
persist-credentials: false
token: ${{ secrets.TALAWA_DOCS_SYNC }}
- name: Empty Commit
run: |
git config --global user.name "${{github.actor}}"
git config --global user.email "${{env.email}}"
git config --global url.https://${{ secrets.TALAWA_DOCS_SYNC }}@github.com/.insteadOf https://github.com/
git commit --allow-empty -m "Trigger Documentation Workflow"
git push origin develop:automated-docs --force
# Copy-docs-to-talawa-docs:
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/automated-docs'
# # needs: Generate-Documentation
# steps:
# - uses: actions/checkout@v3
# - uses: dmnemec/copy_file_to_another_repo_action@v1.1.1
# env:
# API_TOKEN_GITHUB: ${{secrets.TALAWA_DOCS_SYNC}}
# with:
# source_file: 'talawa-api-docs/'
# destination_repo: 'PalisadoesFoundation/talawa-docs'
# destination_branch: 'develop'
# destination_folder: 'docs/'
# user_email: '${{env.email}}'
# user_name: '${{github.actor}}'
# commit_message: 'Talawa API docs updated'
Copy-docs-to-talawa-docs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/automated-docs' && contains(github.event.head_commit.message, 'Trigger Documentation Workflow')
needs : Generate-Documentation
steps:
- uses: actions/checkout@v2
- uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{secrets.TALAWA_DOCS_SYNC}}
with:
source_file: 'talawa-api-docs/'
destination_repo: 'PalisadoesFoundation/talawa-docs'
destination_branch: 'develop'
destination_folder: 'docs/'
user_email: '${{env.email}}'
user_name: '${{github.actor}}'
commit_message: 'Talawa API docs updated'

# You can find the deployment instructions in the scripts/cloud-api-demo/README.md file
Deploy-Workflow:
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion src/models/ActionItemCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { InterfaceUser } from "./User";
import type { InterfaceOrganization } from "./Organization";

/**
* This is an interface that represents a database(MongoDB) document for ActionItemCategory.
* This is an interface that represents a database(MongoDB) document for ActionItemCategory (~Test Check).
*/

export interface InterfaceActionItemCategory {
Expand Down
2 changes: 1 addition & 1 deletion src/models/AgendaCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface InterfaceAgendaCategory {
}

/**
* This is the Mongoose schema for an agenda category.
* This is the Mongoose schema for an agenda category (test-change).
* @param name - Name of the agenda category.
* @param description - Optional description of the agenda category.
* @param organization - Reference to the organization associated with the agenda category.
Expand Down
34 changes: 32 additions & 2 deletions src/resolvers/Mutation/forgotPassword.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import bcrypt from "bcryptjs";
import { jwtDecode } from "jwt-decode";
import { INVALID_OTP } from "../../constants";
import { User } from "../../models";
import type { MutationResolvers } from "../../types/generatedGraphQLTypes";
import { User } from "../../models";
import {
ACCESS_TOKEN_SECRET,
INVALID_OTP,
USER_NOT_FOUND_ERROR,
} from "../../constants";
import jwt from "jsonwebtoken";

/**
* This function enables a user to restore password.
* @param _parent - parent of current request
Expand All @@ -20,7 +26,14 @@ export const forgotPassword: MutationResolvers["forgotPassword"] = async (
) => {
const { userOtp, newPassword, otpToken } = args.data;

try {
await jwt.verify(otpToken, ACCESS_TOKEN_SECRET as string);
} catch (error) {
throw new Error(INVALID_OTP);
}

// Extracts email and otp out of otpToken.

const { email, otp } = jwtDecode<{
email: string;
otp: string;
Expand All @@ -34,6 +47,23 @@ export const forgotPassword: MutationResolvers["forgotPassword"] = async (
throw new Error(INVALID_OTP);
}

const user = await User.findOne({ email }).lean();

if (!user) {
throw new Error(USER_NOT_FOUND_ERROR.MESSAGE);
}
const oldHashedPassword: string = user.password;

//Checks whether the old password is same as the new one
const isSameAsOldPassword = await bcrypt.compare(
newPassword,
oldHashedPassword
);

if (isSameAsOldPassword == true) {
throw new Error("New password cannot be same as old password");
}

const hashedPassword = await bcrypt.hash(newPassword, 12);

// Updates password field for user's document with email === email.
Expand Down
12 changes: 8 additions & 4 deletions src/resolvers/Mutation/updateUserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const updateUserProfile: MutationResolvers["updateUserProfile"] = async (
}

// Update User
const updatedUser = await User.findOneAndUpdate(
let updatedUser = await User.findOneAndUpdate(
{
_id: context.userId,
},
Expand Down Expand Up @@ -128,9 +128,13 @@ export const updateUserProfile: MutationResolvers["updateUserProfile"] = async (
runValidators: true,
},
).lean();
updatedUser!.image = updatedUser?.image
? `${context.apiRootUrl}${updatedUser?.image}`
: null;

if (updatedUser != null) {
updatedUser.image = updatedUser?.image
? `${context.apiRootUrl}${updatedUser?.image}`
: null;
}
if (args.data == undefined) updatedUser = null;

return updatedUser ?? ({} as InterfaceUser);
};
2 changes: 1 addition & 1 deletion src/utilities/copyToClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ncp from "copy-paste";
import { IN_PRODUCTION } from "../constants";
/**
* This utility function copy the text into the clipboard.
* This utility function copy the text into the clipboard (test change).
* @remarks
* This is a utility method. This works only in development or test mode.
* @param text - The content that need to be copied.
Expand Down
Loading

0 comments on commit 605b47f

Please sign in to comment.