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" });
}
};
......@@ -103,7 +103,6 @@ export const signUp = async (req, res) => {
const userDetails = new User({
email,
password: hashedPassword,
type,
userDetails: {
userQNumber: uuidv4(),
userEmail: email,
......@@ -178,53 +177,59 @@ export const updateUser = async (req, res) => {
return res.status(404).json({ code: "02", message: `No User for this id: ${id}` });
}
if (data.type == "buyer" || data.type == "admin") {
const updateUser = { ...data, _id: id }
await User.findByIdAndUpdate(id, updateUser, { new: true })
// if (data.type == "buyer" || data.type == "admin") {
// const updateUser = { ...data, _id: id }
// await User.findByIdAndUpdate(id, updateUser, { new: true })
res.status(200);
res.json({ code: "01", result: updateUser })
// res.status(200);
// res.json({ code: "01", result: updateUser })
} else if (data.type == "trader") {
// } else if (data.type == "trader") {
var password = Math.random().toString(36).slice(-8);
const hashPassword = await bcrypt.hash(password, 12)
const updateUser = { ...data, password: hashPassword, _id: id }
// var password = Math.random().toString(36).slice(-8);
// const hashPassword = await bcrypt.hash(password, 12)
// const updateUser = { ...data, password: hashPassword, _id: id }
await User.findByIdAndUpdate(id, updateUser, { new: true })
// await User.findByIdAndUpdate(id, updateUser, { new: true })
//call email service
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD,
clientId: process.env.OAUTH_CLIENTID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
refreshToken: process.env.OAUTH_REFRESH_TOKEN
}
});
// //call email service
let mailOptions = {
from: "janithgamage1.ed@gmail.com",
to: updateUser.email,
subject: 'Shop House Project',
text: `You are Successfully Approved, you're username: ${updateUser.email} , you're password : ${password}`
};
transporter.sendMail(mailOptions, function (err, data) {
if (err) {
console.log("Error " + err);
} else {
console.log("Email sent successfully");
}
});
// let transporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// type: 'OAuth2',
// user: process.env.MAIL_USERNAME,
// pass: process.env.MAIL_PASSWORD,
// clientId: process.env.OAUTH_CLIENTID,
// clientSecret: process.env.OAUTH_CLIENT_SECRET,
// refreshToken: process.env.OAUTH_REFRESH_TOKEN
// }
// });
// let mailOptions = {
// from: "janithgamage1.ed@gmail.com",
// to: updateUser.email,
// subject: 'Shop House Project',
// text: `You are Successfully Approved, you're username: ${updateUser.email} , you're password : ${password}`
// };
// transporter.sendMail(mailOptions, function (err, data) {
// if (err) {
// console.log("Error " + err);
// } else {
// console.log("Email sent successfully");
// }
// });
// res.status(200);
// 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) {
......
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;
......@@ -11,7 +11,7 @@ const userSchema = mongoose.Schema({
},
type: {
type: String,
required: true
default: "N/A",
},
userDetails: {
userQNumber: {
......@@ -37,7 +37,6 @@ const userSchema = mongoose.Schema({
userType: {
type: String,
default: "N/A",
required: true
},
},
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";
import mongoose from "mongoose";
//import routes
import curriculumRoutes from "./routes/curriculum.routes.js";
import translateRoutes from "./routes/translate.routes.js";
import userRoutes from "./routes/user.routes.js";
dotenv.config();
const app = express();
......@@ -23,6 +25,7 @@ app.get("/", (req, res) => {
//implement routes
app.use("/rest_node/user", userRoutes);
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 PORT = process.env.PORT || 5000;
......
This diff is collapsed.
......@@ -12,6 +12,7 @@ import Scrollbar from 'src/components/scrollbar/Scrollbar';
import { Upload } from 'src/components/upload';
import { NAV } from 'src/config';
import useCountup from 'src/hooks/useCountup';
import CameraCapture from 'src/sections/@dashboard/learning-module/curriculum/CameraCapture';
import { useSettingsContext } from '../../../../../../../components/settings';
import DashboardLayout from '../../../../../../../layouts/dashboard';
......@@ -196,6 +197,7 @@ export default function TutorialViewPage() {
<StyledListContainer>
<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) => {
index = parseInt(item.id)
return (
......@@ -323,7 +325,7 @@ export default function TutorialViewPage() {
<CardHeader title={`${action.toUpperCase()} - ${itemContent?.title}`} />
<CardContent>
<Grid container spacing={3}>
<Grid item md={5}>
<Grid item md={6}>
<ButtonGroup aria-label="outlined button group">
<Button variant={sourceData == "upload" ? "contained" : "outlined"} onClick={() => { setSourceData("upload") }}>Upload Image</Button>
<Button variant={sourceData == "capture" ? "contained" : "outlined"} onClick={() => { setSourceData("capture") }}>Capture Image</Button>
......@@ -331,11 +333,23 @@ export default function TutorialViewPage() {
{!sourceData && <><Alert severity='info'>Select a sourceData Type</Alert></>}
{sourceData == "upload" && <>
<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" && <>
<Card sx={{ mt: 3 }}>
<CardContent>
<Typography variant="h5" paragraph>
{/* <Typography variant="h5" paragraph>
Coming Soon!
</Typography>
......@@ -343,13 +357,14 @@ export default function TutorialViewPage() {
We are currently working hard on this page!
</Typography>
<ComingSoonIllustration sx={{ my: 1, height: 200 }} />
<ComingSoonIllustration sx={{ my: 1, height: 200 }} /> */}
<CameraCapture />
</CardContent>
</Card>
</>}
<Alert severity='info' sx={{ mt: 2 }}>Capture a source</Alert>
</Grid>
<Grid item md={4}>
<Grid item md={6}>
<Grid container spacing={3} rowSpacing={2} sx={{ mt: 8 }}>
<Grid item md={12}>
<TextField
......@@ -382,16 +397,6 @@ export default function TutorialViewPage() {
</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>
</CardContent>
</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:
react-webcam@^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==
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