Commit 5378cc0a authored by janithGamage's avatar janithGamage

fix: update

Desc : update project
parent 8d807298
import mongoose from 'mongoose';
import Curriculum from '../models/curriculum.model.js';
export const getAllCurricula = async (req, res) => {
try {
const curricula = await Curriculum.find();
res.status(200).json({ code: "01", result: curricula });
} catch (error) {
res.status(500).json({ code: "00", message: "Something went wrong" });
}
};
export const getCurriculumById = async (req, res) => {
const { id } = req.params;
try {
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(404).json({ code: "02", message: `No Curriculum for this id: ${id}` });
}
const curriculum = await Curriculum.findById(id);
if (!curriculum) {
return res.status(404).json({ code: "02", message: `No Curriculum found for this id: ${id}` });
}
res.status(200).json({ code: "01", result: curriculum });
} catch (error) {
res.status(500).json({ code: "00", message: "Something went wrong" });
}
};
export const getTutorialsByCurriculumId = async (req, res) => {
const { curriculumId } = req.params;
try {
if (!mongoose.Types.ObjectId.isValid(curriculumId)) {
return res.status(404).json({ code: "02", message: `No Curriculum for this id: ${curriculumId}` });
}
const curriculum = await Curriculum.findById(curriculumId);
if (!curriculum) {
return res.status(404).json({ code: "02", message: `No Curriculum found for this id: ${curriculumId}` });
}
const tutorials = curriculum.tutorials;
res.status(200).json({ code: "01", result: tutorials });
} catch (error) {
res.status(500).json({ code: "00", message: "Something went wrong" });
}
};
export const getTasksByCurriculumAndTutorialId = async (req, res) => {
const { curriculumId, tutorialId } = req.params;
try {
if (!mongoose.Types.ObjectId.isValid(curriculumId)) {
return res.status(404).json({ code: "02", message: `No Curriculum for this id: ${curriculumId}` });
}
const curriculum = await Curriculum.findById(curriculumId);
if (!curriculum) {
return res.status(404).json({ code: "02", message: `No Curriculum found for this id: ${curriculumId}` });
}
const tutorial = curriculum.tutorials.id(tutorialId);
if (!tutorial) {
return res.status(404).json({ code: "02", message: `No Tutorial found for this id: ${tutorialId}` });
}
const tasks = tutorial.tasks;
res.status(200).json({ code: "01", result: tasks });
} catch (error) {
res.status(500).json({ code: "00", message: "Something went wrong" });
}
};
...@@ -102,8 +102,7 @@ export const signUp = async (req, res) => { ...@@ -102,8 +102,7 @@ export const signUp = async (req, res) => {
const userDetails = new User({ const userDetails = new User({
email, email,
password: hashedPassword, password: hashedPassword,
type,
userDetails: { userDetails: {
userQNumber: uuidv4(), userQNumber: uuidv4(),
userEmail: email, userEmail: email,
...@@ -178,53 +177,59 @@ export const updateUser = async (req, res) => { ...@@ -178,53 +177,59 @@ export const updateUser = async (req, res) => {
return res.status(404).json({ code: "02", message: `No User for this id: ${id}` }); return res.status(404).json({ code: "02", message: `No User for this id: ${id}` });
} }
if (data.type == "buyer" || data.type == "admin") { // if (data.type == "buyer" || data.type == "admin") {
const updateUser = { ...data, _id: id } // const updateUser = { ...data, _id: id }
await User.findByIdAndUpdate(id, updateUser, { new: true }) // await User.findByIdAndUpdate(id, updateUser, { new: true })
res.status(200); // res.status(200);
res.json({ code: "01", result: updateUser }) // res.json({ code: "01", result: updateUser })
} else if (data.type == "trader") { // } else if (data.type == "trader") {
var password = Math.random().toString(36).slice(-8); // var password = Math.random().toString(36).slice(-8);
const hashPassword = await bcrypt.hash(password, 12) // const hashPassword = await bcrypt.hash(password, 12)
const updateUser = { ...data, password: hashPassword, _id: id } // const updateUser = { ...data, password: hashPassword, _id: id }
await User.findByIdAndUpdate(id, updateUser, { new: true }) // await User.findByIdAndUpdate(id, updateUser, { new: true })
//call email service // //call email service
let transporter = nodemailer.createTransport({ // let transporter = nodemailer.createTransport({
service: 'gmail', // service: 'gmail',
auth: { // auth: {
type: 'OAuth2', // type: 'OAuth2',
user: process.env.MAIL_USERNAME, // user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD, // pass: process.env.MAIL_PASSWORD,
clientId: process.env.OAUTH_CLIENTID, // clientId: process.env.OAUTH_CLIENTID,
clientSecret: process.env.OAUTH_CLIENT_SECRET, // clientSecret: process.env.OAUTH_CLIENT_SECRET,
refreshToken: process.env.OAUTH_REFRESH_TOKEN // refreshToken: process.env.OAUTH_REFRESH_TOKEN
} // }
}); // });
let mailOptions = { // let mailOptions = {
from: "janithgamage1.ed@gmail.com", // from: "janithgamage1.ed@gmail.com",
to: updateUser.email, // to: updateUser.email,
subject: 'Shop House Project', // subject: 'Shop House Project',
text: `You are Successfully Approved, you're username: ${updateUser.email} , you're password : ${password}` // text: `You are Successfully Approved, you're username: ${updateUser.email} , you're password : ${password}`
}; // };
transporter.sendMail(mailOptions, function (err, data) { // transporter.sendMail(mailOptions, function (err, data) {
if (err) { // if (err) {
console.log("Error " + err); // console.log("Error " + err);
} else { // } else {
console.log("Email sent successfully"); // console.log("Email sent successfully");
} // }
}); // });
res.status(200); // res.status(200);
res.json({ code: "01", result: updateUser }) // res.json({ code: "01", result: updateUser })
} // }
const updateUser = { ...data, _id: id }
await User.findByIdAndUpdate(id, updateUser, { new: true })
res.status(200);
res.json({ code: "01", result: updateUser })
} catch (error) { } catch (error) {
......
import mongoose from "mongoose";
const tutorialSchema = mongoose.Schema({
id: String,
title: String,
description: String,
image: String,
items: [
{
id: String,
title: String,
description: String,
howToDo: [String],
image: String,
video: String,
},
],
});
const curriculumSchema = mongoose.Schema({
id: String,
title: String,
description: String,
image: String,
tutorials: [tutorialSchema],
createdAt: {
type: Date,
default: Date.now,
},
updatedAt: {
type: Date,
default: Date.now,
},
});
const curriculum = mongoose.model("Curriculums", curriculumSchema);
export default curriculum;
...@@ -10,8 +10,8 @@ const userSchema = mongoose.Schema({ ...@@ -10,8 +10,8 @@ const userSchema = mongoose.Schema({
type: String type: String
}, },
type: { type: {
type: String, type: String,
required: true default: "N/A",
}, },
userDetails: { userDetails: {
userQNumber: { userQNumber: {
...@@ -36,8 +36,7 @@ const userSchema = mongoose.Schema({ ...@@ -36,8 +36,7 @@ const userSchema = mongoose.Schema({
}, },
userType: { userType: {
type: String, type: String,
default: "N/A", default: "N/A",
required: true
}, },
}, },
states: { states: {
......
import express from "express";
import { getAllCurricula, getCurriculumById, getTasksByCurriculumAndTutorialId, getTutorialsByCurriculumId } from "../controllers/curriculum.controller.js";
const router = express.Router();
router.get("/", getAllCurricula);
router.get("/:id", getCurriculumById);
router.get("/:curriculumId/tutorials", getTutorialsByCurriculumId);
router.get("/:curriculumId/tutorials/:tutorialId/tasks", getTasksByCurriculumAndTutorialId);
export default router;
...@@ -5,9 +5,11 @@ import express from "express"; ...@@ -5,9 +5,11 @@ import express from "express";
import mongoose from "mongoose"; import mongoose from "mongoose";
//import routes //import routes
import curriculumRoutes from "./routes/curriculum.routes.js";
import translateRoutes from "./routes/translate.routes.js"; import translateRoutes from "./routes/translate.routes.js";
import userRoutes from "./routes/user.routes.js"; import userRoutes from "./routes/user.routes.js";
dotenv.config(); dotenv.config();
const app = express(); const app = express();
...@@ -23,6 +25,7 @@ app.get("/", (req, res) => { ...@@ -23,6 +25,7 @@ app.get("/", (req, res) => {
//implement routes //implement routes
app.use("/rest_node/user", userRoutes); app.use("/rest_node/user", userRoutes);
app.use("/rest_node/ssl", translateRoutes); app.use("/rest_node/ssl", translateRoutes);
app.use("/rest_node/curriculum", curriculumRoutes);
const CONNECTION_URL = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@cluster0.dmza8yi.mongodb.net/?retryWrites=true&w=majority`; const CONNECTION_URL = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@cluster0.dmza8yi.mongodb.net/?retryWrites=true&w=majority`;
const PORT = process.env.PORT || 5000; const PORT = process.env.PORT || 5000;
......
This diff is collapsed.
...@@ -12,6 +12,7 @@ import Scrollbar from 'src/components/scrollbar/Scrollbar'; ...@@ -12,6 +12,7 @@ import Scrollbar from 'src/components/scrollbar/Scrollbar';
import { Upload } from 'src/components/upload'; import { Upload } from 'src/components/upload';
import { NAV } from 'src/config'; import { NAV } from 'src/config';
import useCountup from 'src/hooks/useCountup'; import useCountup from 'src/hooks/useCountup';
import CameraCapture from 'src/sections/@dashboard/learning-module/curriculum/CameraCapture';
import { useSettingsContext } from '../../../../../../../components/settings'; import { useSettingsContext } from '../../../../../../../components/settings';
import DashboardLayout from '../../../../../../../layouts/dashboard'; import DashboardLayout from '../../../../../../../layouts/dashboard';
...@@ -196,6 +197,7 @@ export default function TutorialViewPage() { ...@@ -196,6 +197,7 @@ export default function TutorialViewPage() {
<StyledListContainer> <StyledListContainer>
<List> <List>
{menuItems.length < 0 && <><Alert severity='warning'>No Items for this tutorials</Alert></>}
{menuItems.map((item: { id: string, title: string, onItemClick: any, icon: string, handleCheck: any }, index: number) => { {menuItems.map((item: { id: string, title: string, onItemClick: any, icon: string, handleCheck: any }, index: number) => {
index = parseInt(item.id) index = parseInt(item.id)
return ( return (
...@@ -323,7 +325,7 @@ export default function TutorialViewPage() { ...@@ -323,7 +325,7 @@ export default function TutorialViewPage() {
<CardHeader title={`${action.toUpperCase()} - ${itemContent?.title}`} /> <CardHeader title={`${action.toUpperCase()} - ${itemContent?.title}`} />
<CardContent> <CardContent>
<Grid container spacing={3}> <Grid container spacing={3}>
<Grid item md={5}> <Grid item md={6}>
<ButtonGroup aria-label="outlined button group"> <ButtonGroup aria-label="outlined button group">
<Button variant={sourceData == "upload" ? "contained" : "outlined"} onClick={() => { setSourceData("upload") }}>Upload Image</Button> <Button variant={sourceData == "upload" ? "contained" : "outlined"} onClick={() => { setSourceData("upload") }}>Upload Image</Button>
<Button variant={sourceData == "capture" ? "contained" : "outlined"} onClick={() => { setSourceData("capture") }}>Capture Image</Button> <Button variant={sourceData == "capture" ? "contained" : "outlined"} onClick={() => { setSourceData("capture") }}>Capture Image</Button>
...@@ -331,11 +333,23 @@ export default function TutorialViewPage() { ...@@ -331,11 +333,23 @@ export default function TutorialViewPage() {
{!sourceData && <><Alert severity='info'>Select a sourceData Type</Alert></>} {!sourceData && <><Alert severity='info'>Select a sourceData Type</Alert></>}
{sourceData == "upload" && <> {sourceData == "upload" && <>
<Upload sx={{ mt: 3 }} file={file} onDrop={handleDropSingleFile} onDelete={() => setFile(null)} /> <Upload sx={{ mt: 3 }} file={file} onDrop={handleDropSingleFile} onDelete={() => setFile(null)} />
{/* {file != null &&
<>
<Image
disabledEffect
alt={"Reference Image"}
src={"https://drive.google.com/uc?export=view&id=1T7djlWSfUgCFUNrrW5teXUJglZ-uTHLk"}
ratio={"1/1"}
sx={{ borderRadius: 1, mt: 6 }}
/>
<Alert severity='info' sx={{ mt: 2 }}>Captured source</Alert>
</>
} */}
</>} </>}
{sourceData == "capture" && <> {sourceData == "capture" && <>
<Card sx={{ mt: 3 }}> <Card sx={{ mt: 3 }}>
<CardContent> <CardContent>
<Typography variant="h5" paragraph> {/* <Typography variant="h5" paragraph>
Coming Soon! Coming Soon!
</Typography> </Typography>
...@@ -343,13 +357,14 @@ export default function TutorialViewPage() { ...@@ -343,13 +357,14 @@ export default function TutorialViewPage() {
We are currently working hard on this page! We are currently working hard on this page!
</Typography> </Typography>
<ComingSoonIllustration sx={{ my: 1, height: 200 }} /> <ComingSoonIllustration sx={{ my: 1, height: 200 }} /> */}
<CameraCapture />
</CardContent> </CardContent>
</Card> </Card>
</>} </>}
<Alert severity='info' sx={{ mt: 2 }}>Capture a source</Alert> <Alert severity='info' sx={{ mt: 2 }}>Capture a source</Alert>
</Grid> </Grid>
<Grid item md={4}> <Grid item md={6}>
<Grid container spacing={3} rowSpacing={2} sx={{ mt: 8 }}> <Grid container spacing={3} rowSpacing={2} sx={{ mt: 8 }}>
<Grid item md={12}> <Grid item md={12}>
<TextField <TextField
...@@ -382,16 +397,6 @@ export default function TutorialViewPage() { ...@@ -382,16 +397,6 @@ export default function TutorialViewPage() {
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
<Grid item md={3}>
<Image
disabledEffect
alt={"Reference Image"}
src={"https://drive.google.com/uc?export=view&id=1T7djlWSfUgCFUNrrW5teXUJglZ-uTHLk"}
ratio={"1/1"}
sx={{ borderRadius: 1, mt: 6 }}
/>
<Alert severity='info' sx={{ mt: 2 }}>Captured source</Alert>
</Grid>
</Grid> </Grid>
</CardContent> </CardContent>
</Card> </Card>
......
import React, { useRef, useState } from 'react';
import Webcam from 'react-webcam';
import Button from '@mui/material/Button';
const CameraCapture: React.FC = () => {
const webcamRef = useRef<Webcam>(null);
const [capturedImage, setCapturedImage] = useState<string | null>(null);
const capture = () => {
if (webcamRef.current) {
const imageSrc = webcamRef.current.getScreenshot();
setCapturedImage(imageSrc);
}
};
return (
<div>
<Webcam audio={false} ref={webcamRef} screenshotFormat="image/jpeg" />
<Button variant="contained" onClick={capture} fullWidth>
Capture
</Button>
{capturedImage && (
<div>
<h2>Captured Image:</h2>
<img src={capturedImage} alt="Captured" />
</div>
)}
</div>
);
};
export default CameraCapture;
...@@ -4706,7 +4706,7 @@ react-transition-group@^4.4.5: ...@@ -4706,7 +4706,7 @@ react-transition-group@^4.4.5:
react-webcam@^7.0.1: react-webcam@^7.0.1:
version "7.0.1" version "7.0.1"
resolved "https://registry.npmjs.org/react-webcam/-/react-webcam-7.0.1.tgz" resolved "https://registry.yarnpkg.com/react-webcam/-/react-webcam-7.0.1.tgz#8249e1d621eb4bba7e3f52135f562439d0528df3"
integrity sha512-8E/Eb/7ksKwn5QdLn67tOR7+TdP9BZdu6E5/DSt20v8yfW/s0VGBigE6VA7R4278mBuBUowovAB3DkCfVmSPvA== integrity sha512-8E/Eb/7ksKwn5QdLn67tOR7+TdP9BZdu6E5/DSt20v8yfW/s0VGBigE6VA7R4278mBuBUowovAB3DkCfVmSPvA==
react@^18.2.0: react@^18.2.0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment