Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenilk committed Apr 30, 2023
0 parents commit e993a3b
Show file tree
Hide file tree
Showing 1,759 changed files with 346,720 additions and 0 deletions.
120 changes: 120 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const port = 3000;
var bodyParser = require('body-parser');
mongoose.connect("mongodb+srv://Lenilk:[email protected]/Refrigurator");
const databased = mongoose.connection;
const InRefrigurator = require("./model/inRefriguratorModel");
const Want = require("./model/wantModel");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
databased.on('error', (error) => {
console.log(error);
});
databased.once('connected', () => {
console.log('Database Connected');
});
app.get("/getRf", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const data = yield InRefrigurator.find();
res.json(data);
}
catch (error) {
res.status(500).json({ message: error.message });
}
}));
app.get("/getWant", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const data = yield Want.find();
res.json(data);
}
catch (error) {
res.status(500).json({ message: error.message });
}
}));
app.post("/postRf", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const data = InRefrigurator({
name: req.body.name,
Amount: req.body.Amount
});
try {
const dataToSave = yield data.save();
res.status(200).json(dataToSave);
}
catch (error) {
res.status(400).json({ message: error.message });
}
}));
app.post("/postWant", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const data = Want({
name: req.body.name,
Amount: req.body.Amount,
Comment: req.body.Comment
});
try {
const dataToSave = yield data.save();
res.status(200).json(dataToSave);
}
catch (error) {
res.status(400).json({ message: error.message });
}
}));
app.delete("/deleteRf/:id", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const id = req.params.id;
const data = yield InRefrigurator.findByIdAndDelete(id);
res.send(`Document with ${data.name} has been deleted..`);
}
catch (error) {
res.status(400).json({ message: error.message });
}
}));
app.delete("/deleteWant/:id", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const id = req.params.id;
const data = yield Want.findByIdAndDelete(id);
res.send(`Document with ${data.name} has been deleted..`);
}
catch (error) {
res.status(400).json({ message: error.message });
}
}));
app.patch('/updateRf/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const id = req.params.id;
const updatedData = req.body;
const options = { new: true };
const result = yield InRefrigurator.findByIdAndUpdate(id, updatedData, options);
res.send(result);
}
catch (error) {
res.status(400).json({ message: error.message });
}
}));
app.patch('/updateWant/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const id = req.params.id;
const updatedData = req.body;
const options = { new: true };
const result = yield Want.findByIdAndUpdate(id, updatedData, options);
res.send(result);
}
catch (error) {
res.status(400).json({ message: error.message });
}
}));
app.listen(port, () => {
console.log(`start in ${port}`);
});
133 changes: 133 additions & 0 deletions api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { Response,Request } from "express";
const express= require("express");
const mongoose = require("mongoose");
const app =express();
const port =3000;
var bodyParser = require('body-parser')
mongoose.connect("mongodb+srv://Lenilk:[email protected]/Refrigurator");
const databased = mongoose.connection
const InRefrigurator=require("./model/inRefriguratorModel");
const Want=require("./model/wantModel");
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))


databased.on('error', (error:Error) => {
console.log(error)
})

databased.once('connected', () => {
console.log('Database Connected');
})


app.get("/getRf",async(req:Request,res:Response)=>{
try{
const data = await InRefrigurator.find();
res.json(data)
}
catch(error:any){
res.status(500).json({message: error.message})
}
})

app.get("/getWant",async(req:Request,res:Response)=>{
try{
const data = await Want.find();
res.json(data)
}
catch(error:any){
res.status(500).json({message: error.message})
}
})


app.post("/postRf", async(req:Request,res:Response)=>{
const data= InRefrigurator({
name:req.body.name,
Amount:req.body.Amount
})
try {
const dataToSave = await data.save();
res.status(200).json(dataToSave)
}
catch (error:any) {
res.status(400).json({message: error.message})
}
})

app.post("/postWant",async(req:Request,res:Response)=>{
const data= Want({
name:req.body.name,
Amount:req.body.Amount,
Comment:req.body.Comment
})
try {
const dataToSave = await data.save();
res.status(200).json(dataToSave)
}
catch (error:any) {
res.status(400).json({message: error.message})
}
})


app.delete("/deleteRf/:id",async(req:Request,res:Response)=>{
try {
const id = req.params.id;
const data = await InRefrigurator.findByIdAndDelete(id)
res.send(`Document with ${data.name} has been deleted..`)
}
catch (error:any) {
res.status(400).json({ message: error.message })
}
})

app.delete("/deleteWant/:id",async(req:Request,res:Response)=>{
try {
const id = req.params.id;
const data = await Want.findByIdAndDelete(id)
res.send(`Document with ${data.name} has been deleted..`)
}
catch (error:any) {
res.status(400).json({ message: error.message })
}
})

app.patch('/updateRf/:id', async (req:Request, res:Response) => {
try {
const id = req.params.id;
const updatedData = req.body;
const options = { new: true };

const result = await InRefrigurator.findByIdAndUpdate(
id, updatedData, options
)

res.send(result)
}
catch (error:any) {
res.status(400).json({ message: error.message })
}
})

app.patch('/updateWant/:id', async (req:Request, res:Response) => {
try {
const id = req.params.id;
const updatedData = req.body;
const options = { new: true };

const result = await Want.findByIdAndUpdate(
id, updatedData, options
)

res.send(result)
}
catch (error:any) {
res.status(400).json({ message: error.message })
}
})

app.listen(port,()=>{
console.log(`start in ${port}`);
})
1 change: 1 addition & 0 deletions database.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=mongodb+srv://Lenilk:[email protected]/Refrigurator
13 changes: 13 additions & 0 deletions model/inRefriguratorModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mongoose = require("mongoose");

const InRefrigurator = mongoose.Schema({
name:{
required:true,
type:String
},
Amount:{
required:true,
type:String
}
});
module.exports =mongoose.model("InRefrigurator",InRefrigurator);
17 changes: 17 additions & 0 deletions model/wantModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require("mongoose");

const Want = mongoose.Schema({
name:{
required:true,
type:String
},
Amount:{
required:true,
type:String
},
Comment:{
type:String,
default:""
}
});
module.exports =mongoose.model("Want",Want);
12 changes: 12 additions & 0 deletions node_modules/.bin/mime

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

17 changes: 17 additions & 0 deletions node_modules/.bin/mime.cmd

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

28 changes: 28 additions & 0 deletions node_modules/.bin/mime.ps1

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

12 changes: 12 additions & 0 deletions node_modules/.bin/nodemon

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

17 changes: 17 additions & 0 deletions node_modules/.bin/nodemon.cmd

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

Loading

2 comments on commit e993a3b

@vercel
Copy link

@vercel vercel bot commented on e993a3b Apr 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

refrigurator-api – ./

refrigurator-api.vercel.app
refrigurator-api-lenilk.vercel.app
refrigurator-api-git-main-lenilk.vercel.app

@vercel
Copy link

@vercel vercel bot commented on e993a3b Apr 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.