This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
179 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var notyf = new Notyf(); | ||
var modelBtn = document.getElementById("modelBtn"); | ||
|
||
modelBtn.addEventListener("click", (e) => { | ||
e.preventDefault(); | ||
let name = document.getElementById("name").value; | ||
let descriptipn = document.getElementById("description").value; | ||
fetch("/dashboard/model/new", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
name: name, | ||
description: description, | ||
}), | ||
}).catch((err) => console.log(err)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var notyf = new Notyf(); | ||
var buyBtn = document.querySelector("#buyBtn"); | ||
|
||
buyBtn.addEventListener("click", (e) => { | ||
e.preventDefault(); | ||
let modelType = document.querySelector("#modelType").value; | ||
let modelName = document.querySelector("#modelName").value; | ||
fetch("/market/buy", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
modelType: modelType, | ||
modelName: modelName, | ||
}), | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
if (data.status === 400) { | ||
notyf.error(data.message); | ||
} else { | ||
setTimeout(() => { | ||
notyf.success(data.message); | ||
}, 3000); | ||
window.location.href = "/dashboard"; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const template = require("../schemas/templateSchema"); | ||
const { checkUser } = require("../services/auth"); | ||
const { checkUser } = require("../middleware/auth"); | ||
|
||
router.get("/", checkUser, async (req, res) => { | ||
const templates = await template.find(); | ||
res.render("dashboard/index", { templates }); | ||
}); | ||
|
||
// Model Section | ||
router.post("/model/new", async (req, res) => { | ||
const { name, description } = req.body; | ||
const newTemplate = new template({ | ||
name, | ||
description, | ||
}); | ||
newTemplate.save(); | ||
res.cookie("modelId", newTemplate._id, { | ||
httpOnly: true, | ||
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), | ||
}); | ||
return res.redirect("/dashboard/model/pref/1"); | ||
}); | ||
router.get("/dashboard/model/pref/1", checkUser, async (req, res) => { | ||
res.render("model/pref/1"); | ||
}); | ||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const router = require("express").Router(); | ||
const { checkUser } = require("../middleware/auth"); | ||
const template = require("../schemas/templateSchema"); | ||
const user = require("../schemas/userSchema"); | ||
|
||
router.get("/", checkUser, (req, res) => { | ||
console.log(req.user); | ||
res.render("market/index"); | ||
}); | ||
|
||
router.post("/buy", checkUser, async (req, res) => { | ||
try { | ||
const { modelType, modelName } = req.body; | ||
let modelLink = ""; | ||
if (modelType === "house") { | ||
// DUMMY LINK TO BE REPLACED WITH ACTUAL MODEL KA GDRIVE LINK | ||
modelLink = "https://google.com"; | ||
} | ||
const userId = req.user["_id"]; | ||
const savedUser = await user.findById(userId); | ||
const credits = savedUser.credits; | ||
if (credits < 30) { | ||
return res.status(400).json({ | ||
msg: "Not enough credits", | ||
}); | ||
} else { | ||
const newUser = await user.findByIdAndUpdate(userId, { | ||
$inc: { credits: -30 }, | ||
}); | ||
} | ||
|
||
const newTemplate = new template({ | ||
model: modelLink, | ||
name: modelName, | ||
userId, | ||
credits: 30, | ||
}); | ||
await newTemplate.save(); | ||
|
||
return res.status(200).send({ | ||
msg: "Model purchased", | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
return res.status(400).status({ | ||
msg: "Some Error Occurred", | ||
}); | ||
} | ||
}); | ||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h1>Market Place</h1> | ||
|
||
<h2>Available Models</h2> | ||
|
||
<p> | ||
1. House <br> | ||
<!-- MODEL PREVIEW HERE WITH IMAGE --> | ||
<!-- DESIGN SIMILAR TO AMAZON/FLIPKART ETC --> | ||
Base Price: 30 Credits <br> | ||
<form action="buyForm"> | ||
<input name="modelType" id="modelType" hidden> | ||
<input name="modelName" id="modelName" type="text" required placeholder="Model Name"> <br><br> | ||
<button id="buyBtn">Buy Base Model Template</button> | ||
</forma> | ||
</p> | ||
<script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script> | ||
<script src="/js/market.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Q1: Which do you like more ?</h1> | ||
|
||
<!-- form with 2 radio buttons --> | ||
<form id="q1"> | ||
<input type="radio" name="q1" value="a"> A: <input type="text" name="a" id="a"> <br> | ||
<input type="radio" name="q1" value="b"> B: <input type="text" name="b" id="b"> <br> | ||
</form> |