Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions webhooks/application1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
1,740 changes: 1,740 additions & 0 deletions webhooks/application1/package-lock.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions webhooks/application1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "folder_structure",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "tsc && node ./dist/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/bcrypt": "^5.0.0",
"@types/node": "^20.4.8",
"typescript": "^5.1.6"
},
"dependencies": {
"@types/express": "^4.17.17",
"amqplib": "^0.10.3",
"axios": "^1.4.0",
"bcrypt": "^5.1.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mongoose": "^7.4.2",
"node-cron": "^3.0.2"
}
}
4 changes: 4 additions & 0 deletions webhooks/application1/src/config/dotenv.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// require("dotenv").config();
import dotenv from "dotenv";

dotenv.config();
21 changes: 21 additions & 0 deletions webhooks/application1/src/controller/auth.controler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Response, Request } from "express";


import { writeErrorToFile } from "../node-cron/error_write";
import { signUp } from "../services/auth.services";


export const signup = async (req: Request, res: Response) => {
try {
const { name, email, username, password, phone_no } = req.body;

const user = await signUp(name, email, username, password, phone_no);


res.status(201).json({ message: "User Signup successfully application 1" });
} catch (e) {
console.error(e);
res.status(500).json({ message: "Internal server error" });
writeErrorToFile(e);
}
};
12 changes: 12 additions & 0 deletions webhooks/application1/src/database/dbconnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mongoose from "mongoose";
import "../config/dotenv.config";
const url = process.env.DB_CONNECTION_URL;

export const connection = async () => {
try {
await mongoose.connect(url);
console.log("Succesfully connected to the db");
} catch (e) {
console.log(e, "ERRRRRR");
}
};
17 changes: 17 additions & 0 deletions webhooks/application1/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import express from "express";
import { connection } from "./database/dbconnection";
import signUp from "./routes/user.rotes";
import { task } from "./node-cron/delete_error";
import dotenv from "dotenv";

dotenv.config();
const app = express();
const port = process.env.PORT || 3001;
app.use(express.json());
app.use(signUp);

app.listen(port, () => {
// task
console.log(`port is running in ${port}`);
connection();
});
Empty file.
24 changes: 24 additions & 0 deletions webhooks/application1/src/models/user.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mongoose, { Document, Schema } from "mongoose";
interface User extends Document {
name: string;
email: string;
username: string;
password: string;
phone_no: string;
created_At: Date;
updated_At: Date;
}

const userSchema: Schema<User> = new Schema<User>({
name: { type: String, required: true },
email: { type: String, required: true },
username: { type: String, required: true },
password: { type: String, required: true },
phone_no: { type: String, required: true },
created_At: { type: Date, default: Date.now },
updated_At: { type: Date, default: Date.now },
});

const UserModel = mongoose.model<User>("User", userSchema);

export default UserModel;
15 changes: 15 additions & 0 deletions webhooks/application1/src/node-cron/delete_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "fs";
import cron from "node-cron";
import path from "path";

export const task = cron.schedule("* */2 * * * ", () => {
const filePath = path.join(__dirname, "../../error.log");
console.log(filePath);
fs.unlink(filePath, (err) => {
if (err) {
console.error(err);
return;
}
console.log(`Deleted ${filePath}`);
});
});
10 changes: 10 additions & 0 deletions webhooks/application1/src/node-cron/error_write.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fs from "fs";

export function writeErrorToFile(error) {
const errorMessage = `${new Date().toISOString()} - ${error.stack}\n`;
try {
fs.appendFileSync("error.log", errorMessage);
} catch (error) {
console.error(`Error writing to file: ${error.message}`);
}
}
9 changes: 9 additions & 0 deletions webhooks/application1/src/routes/user.rotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from "express";
import { signup } from "../controller/auth.controler";

const router = express.Router();

router.post("/signup", signup);


export default router;
46 changes: 46 additions & 0 deletions webhooks/application1/src/services/auth.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import axios from "axios";
import UserModel from "../models/user.model";

import bcrypt from "bcrypt";

export async function signUp(
name: string,
email: string,
username: string,
password: string,
phone_no: bigint
): Promise<any> {
try {
const hashedPassword = await bcrypt.hash(password, 2);

const users = new UserModel({
name: name,
email: email,
username: username,
password: hashedPassword,
phone_no: phone_no,
});

console.log(users);
await users.save();

axios
.post("http://localhost:3001/signup", {
name: name,
email: email,
username: username,
password: password,
phone_no: phone_no,
})
.then(function (response) {
console.log("==========", response.data);
})
.catch(function (error) {
console.log(error);
});
} catch (e) {
console.error("error creating user :", e);
throw new Error("hi error a gya ");
}
}

12 changes: 12 additions & 0 deletions webhooks/application1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions":{
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target":"ES2020",
"sourceMap": true,
"outDir": "dist",
},

"include": ["src/**/*"],
"resolveJsonModule": true
}
3 changes: 3 additions & 0 deletions webhooks/application2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
Loading