Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
ARAVIND1828 committed Jun 20, 2023
1 parent ba228e6 commit 91f2290
Show file tree
Hide file tree
Showing 96 changed files with 26,024 additions and 385 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/main_backendvetmedtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js app to Azure Web App - Backendvetmedtest

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js version
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: node-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: node-app

- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'Backendvetmedtest'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_B6303C6D214443FE9541AB333A2ECB26 }}
package: .
753 changes: 753 additions & 0 deletions README.md

Large diffs are not rendered by default.

61 changes: 0 additions & 61 deletions app.js

This file was deleted.

53 changes: 53 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const express = require("express");
const app = express();
const errorMiddleware = require("./middleware/error");
const cookieParser = require("cookie-parser");
const dotenv = require("dotenv");
const cors = require("cors");

// Config
dotenv.config({ path: "backend/config/config.env" });

app.use(cors());

app.use(cookieParser());
app.use(express.json());

//Route Imports
const user = require("./routes/userRoutes");
const animalType = require("./routes/categories/animalTypeRoutes");
const treatmentType = require("./routes/categories/treatmentTypeRoute");
const product = require("./routes/productsRoute");
const essential = require("./routes/categories/dailyEssentialRoutes");
const medical = require("./routes/categories/medicalCareRoute");
const order = require("./routes/orderRoutes");
const varieties = require("./routes/varietyRoutes");
const contactUs = require("./routes/contactUsRoutes");
const healthCheck = require("./routes/healthCheckRoutes");

app.use("/api/v1", user);
app.use("/api/v1", animalType);
app.use("/api/v1", treatmentType);
app.use("/api/v1", product);
app.use("/api/v1", essential);
app.use("/api/v1", medical);
app.use("/api/v1", order);
app.use("/api/v1", varieties);
app.use("/api/v1", contactUs);
app.use("/api/v1", healthCheck);

app.use("*", (req, res) => {
res.status(404).json({
success: false,
errors: [
{
msg: "Route Not found",
},
],
});
});

//Middleware for error
app.use(errorMiddleware);

module.exports = app;
16 changes: 16 additions & 0 deletions backend/config/config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PORT = 4000
MONGO_URL = mongodb+srv://vetmedman501:[email protected]/vetmedman?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true


JWT_SECRET = secreatkeycanberandom

JWT_EXPIRE = 5d

COOKIE_EXPIRES = 5

SMPT_SERVICE=gmail

SMPT_MAIL=[email protected]
SMPT_PASSWORD =pnktxnhntrmtiixj
SMPT_HOST=smpt.gmail.com
FRONTEND_URL = "http://localhost:3000"
124 changes: 124 additions & 0 deletions backend/controllers/categories/animalController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
const Animal = require('../../models/categories/animal');
const catchAsyncErrors = require('../../middleware/catchAsyncError');

/**
* This function creates a new animal category. It checks if the animalName already exists in the database (case-insensitive). If it exists, it returns an error message. Otherwise, it creates a new animal category using the Animal model with the provided animalName, imageUrl, and user (from req.user.id). It responds with a success message and the created animal category.
*
* @param {Object} req - The request object.
* @param {Object} req.body - The request body containing the animalName and imageUrl.
* @param {string} req.body.animalName - The name of the animal.
* @param {string} req.body.imageUrl - The URL of the image for the animal.
* @param {Object} res - The response object.
* @param {Function} next - The next middleware function.
* @returns {Object} - The JSON response indicating the success status and the created animal category.
* @throws {Error} - If an error occurs while creating the animal category.
*/

//Create animal category
exports.createAnimalType = catchAsyncErrors(async (req, res, next) => {
try {
const animalName = req.body.animalName;
const imageUrl = req.body.imageUrl;

// Check if the animalName already exists in the database (case-insensitive)
const existingAnimal = await Animal.findOne({ animalName: { $regex: new RegExp(`^${animalName}$`, "i") } });

if (existingAnimal) {
return res.status(400).json({
success: false,
message: "Animal type already exists"
});
}

// Create a new animal type
const animalT = await Animal.create({
animalName,
imageUrl,
user: req.user.id
});

res.status(201).json({
success: true,
animalT
});
} catch (error) {
next(error);
}
});


/**
* This function retrieves all animal categories from the database using the Animal model. It responds with a success message and an array of animal categories.
*
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {Function} next - The next middleware function.
* @returns {Object} - The JSON response containing the retrieved animal categories.
* @throws {Error} - If an error occurs while retrieving the animal categories.
*/

//get all animals category
exports.allAnimalType = catchAsyncErrors(async (req, res, next) => {
try {
const animalT = await Animal.find();
res.status(200).json({
success: true,
animalT
})
} catch (error) {
next(error);
}
})


/**
* This function updates an existing animal category. It finds the animal category by its ID (type_id parameter) and updates it with the data from req.body. The { new: true } option ensures that the updated animal category is returned as the response. It responds with a success message and the updated animal category.
*
* @param {Object} req - The request object.
* @param {Object} req.params - The parameters extracted from the URL.
* @param {string} req.params.type_id - The ID of the animal category to update.
* @param {Object} req.body - The request body containing the updated data for the animal category.
* @param {Object} res - The response object.
* @param {Function} next - The next middleware function.
* @returns {Object} - The JSON response indicating the success status and the updated animal category.
* @throws {Error} - If an error occurs while updating the animal category.
*/

//update animal type
exports.updateAnimalType = async (req, res, next) => {
try {
const animalT = await Animal.findByIdAndUpdate(req.params.type_id, req.body, { new: true });
res.status(200).json({
success: true,
animalT
})
} catch (error) {
next(error);
}
}


/**
* This function deletes an animal category. It finds the animal category by its ID (type_id parameter) and removes it from the database. It responds with a success message and the deleted animal category.
*
* @param {Object} req - The request object.
* @param {Object} req.params - The parameters extracted from the URL.
* @param {string} req.params.type_id - The ID of the animal category to delete.
* @param {Object} res - The response object.
* @param {Function} next - The next middleware function.
* @returns {Object} - The JSON response indicating the success status and the deleted animal category.
* @throws {Error} - If an error occurs while deleting the animal category.
*/

//delete animal type
exports.deleteAnimalType = async (req, res, next) => {
try {
const animalT = await Animal.findByIdAndRemove(req.params.type_id);
res.status(200).json({
success: true,
animalT
})
} catch (error) {
next(error);
}
}
Loading

0 comments on commit 91f2290

Please sign in to comment.