Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgonzaDJun authored Dec 2, 2023
2 parents b73c037 + befd798 commit 9f0bfdb
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 22 deletions.
3 changes: 1 addition & 2 deletions controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ const register = async (req, res) => {
}

const hashPassword = bcrypt.hashSync(data.password, 10);
data.password = hashPassword;

const user = await User.create({
username,
fullname,
email,
no_hp,
password: hashPassword,
otp
});

res.status(201).json({
Expand Down
69 changes: 63 additions & 6 deletions controllers/booking.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
const data = await Booking.create({
user_id,
conselor_id,
tanggal_konseling: new Date(),
tanggal_konseling,
media_konseling,
link_konseling: zoomMeeting,
kode_pembayaran,
Expand All @@ -53,7 +53,7 @@ module.exports = {
const data = await Booking.create({
user_id,
conselor_id,
tanggal_konseling: new Date(),
tanggal_konseling,
media_konseling,
kode_pembayaran,
status: "pending",
Expand All @@ -72,6 +72,62 @@ module.exports = {
}
},

getBookingById: async (req, res) => {
const { id } = req.params;

try {
const data = await Booking.findById(id)
.populate("user_id")
.populate({
path: "conselor_id",
populate: {
path: "user_id",
select: "fullname",
},
})
.exec();

res.json({
message: "Data booking by booking id berhasil didapatkan",
data,
});
} catch (error) {
res.status(500).json({
message: "Terjadi error",
error: error.message,
});
}
},

getBookingByUserId: async (req, res) => {
const user = req.user;

const user_id = user.id;

try {
const data = await Booking.find({ user_id })
.populate("user_id")
.populate({
path: "conselor_id",
populate: {
path: "user_id",
select: "fullname",
},
})
.exec();

res.json({
message: "Data booking by user id berhasil didapatkan",
data,
});
} catch (error) {
res.status(500).json({
message: "Terjadi error",
error: error.message,
});
}
},

readBooking: async (req, res) => {
try {
const data = await Booking.find().sort({ createdAt: -1 });
Expand All @@ -94,17 +150,18 @@ module.exports = {
const { status, tanggal_konseling } = req.body;

try {
const data = await Booking.findByIdAndUpdate(
{ _id: id },
const data = await Booking.findOneAndUpdate(
{ kode_pembayaran: id },
{
status,
tanggal_konseling,
}
);

const findBook = await Booking.findOne({ kode_pembayaran: id });

res.json({
message: "Booking berhasil diupdate",
data,
data: findBook,
});
} catch (error) {
res.status(500).json({
Expand Down
6 changes: 3 additions & 3 deletions controllers/conselor.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const User = require("../models/user");
// getAllConselor
const getConselor = async (req, res) => {
try {
const conselorsData = await Conselor.find();
const conselorsData = await Conselor.find().populate("user_id").exec();

res.status(200).json({
status: "OK",
Expand Down Expand Up @@ -54,7 +54,7 @@ const registConselor = async (req, res) => {
const getConselorById = async (req, res) => {
const { id } = req.params;
try {
const conselor = await Conselor.findById(id);
const conselor = await Conselor.findById(id).populate("user_id").exec();

if (!conselor) {
return res.status(400).json({
Expand Down Expand Up @@ -250,5 +250,5 @@ module.exports = {
saveSchedule,
updateSchedule,
addPrice,
updatePrice
updatePrice,
};
8 changes: 5 additions & 3 deletions controllers/payment-xendit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ module.exports = {
invoiceExpired: ["sms", "whatsapp", "email"],
},

successRedirectUrl: "https://www.google.com",
failureRedirectUrl: "https://www.google.com",
successRedirectUrl: process.env.FRONTEND_URL + "/history/" + external_id,
failureRedirectUrl: process.env.FRONTEND_URL + "/history/" + external_id + "/fail",
};

const invoice = await xenditInvoiceClient.createInvoice({ data: data2 });
Expand All @@ -80,7 +80,9 @@ module.exports = {

getInvoices: async (req, res) => {
try {
const response = await xenditInvoiceClient.getInvoices({});
const response = await xenditInvoiceClient.getInvoices({
limit: 100,
});
res.status(200).json({
message: "Berhasil mendapatkan data invoice",
data: response,
Expand Down
23 changes: 20 additions & 3 deletions controllers/story.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ module.exports = {
story.isLike = story.likes.some(
(like) => like.user._id.toString() === userId
);
story.likes = story.likes.length;
story.comments = story.comments.length;
});

return res.status(200).json({
Expand All @@ -51,12 +49,31 @@ module.exports = {
},

getStoryById: async (req, res) => {
const header = req.headers.authorization;
const token = header.split(" ")[1];
const decoded = jwt.verify(token, "treasure");
const userId = decoded.id;

const { id } = req.params;
if (!id) {
return badRequest(res);
}
try {
const story = await Story.findById(id);
const story = await Story.findById(id)
.populate({
path: "user",
select: "username",
})
.populate({
path: "comments.user",
select: "username",
})
.lean();
story.isLike = story.likes.some(
(like) => like.user._id.toString() === userId
);
story.likes = story.likes.length;

return res.status(200).json({
status: "OK",
message: "Get Data Story Successfully",
Expand Down
2 changes: 1 addition & 1 deletion controllers/zoom.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.createMeeting = async (topic, duration, start_time) => {
const content = {
meeting_url: response_data.join_url,
password: response_data.password,
meetingTime: response_data.start_time,
meetingTime: start_time,
purpose: response_data.topic,
duration: response_data.duration,
message: "Success",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion routes/booking.route.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const express = require("express");
const { createBooking, readBooking, updateBooking, deleteBooking } = require("../controllers/booking.controller");
const { createBooking, readBooking, updateBooking, deleteBooking, getBookingById, getBookingByUserId } = require("../controllers/booking.controller");
const authToken = require("../middlewares/auth");
const router = express.Router();

router.post("/", authToken, createBooking);
router.get("/", readBooking);
router.get("/user", authToken, getBookingByUserId);
router.get("/:id", getBookingById);
router.put("/:id", updateBooking);
router.delete("/:id", deleteBooking);

Expand Down

0 comments on commit 9f0bfdb

Please sign in to comment.