Skip to content

Commit

Permalink
#97 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
fdhhhdjd committed Oct 26, 2022
1 parent edc4b9b commit fccd930
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const mongoose = require("mongoose");
const Products = require("../../../models/ProductModel");
const HELPER = require("../../../utils/helper");
const CONTAINS = require("../../../configs/constants");
const { set, del } = require("../../../utils/limited_redis");
const REDIS = require("../../../db/redis_db");
module.exports = {
createReview: async (product, review) => {
const sess = await mongoose.startSession();
Expand Down Expand Up @@ -107,14 +107,15 @@ module.exports = {
},
};
const resetRedisProduct = async () => {
await del("product_user");
const random_number = HELPER.randomNumber();
const product_user = await Products.find().sort({
createdAt: 1,
});
await set(
"product_user",
JSON.stringify(product_user),
CONTAINS._1_DAYS_REDIS + random_number
);
REDIS.pipeline()
.del("product_user")
.set(
"product_user",
JSON.stringify(product_user),
CONTAINS._1_DAYS_REDIS + random_number
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const Users = require("../../../models/userModel");
const UserVerifications = require("../../../models/userVerificationModel");
const CONSTANTS = require("../../../configs/constants");
const HELPER = require("../../../utils/helper");
const { RedisPub } = require("../../../utils/limited_redis");
const {
destroyStorage,
} = require("../../../upload_cloudinary/services/uploadStorage.service");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Orders = require("../../../models/PaymentModel");
const HELPER = require("../../../utils/helper");
const CONTAINS = require("../../../configs/constants");
const { set, get, del } = require("../../../utils/limited_redis");
const REDIS = require("../../../db/redis_db");
const getProfileId = async (userId) => {
const user_redis = await get(`userId:${userId}`);
if (user_redis) {
Expand Down Expand Up @@ -31,17 +32,18 @@ const getOrderInfoEveryUser = async (userId) => {
};

const updateProfileId = async (userId) => {
await del(`userId:${userId}`);
const random_number = HELPER.randomNumber();
const user = await Users.findById(userId).select("+password");
if (user) {
await set(
let redis_multi = REDIS.pipeline()
.del(`userId:${userId}`)
.set(
`userId:${userId}`,
JSON.stringify(user),
CONTAINS._1_DAYS_REDIS + random_number
);
}
return user;
redis_multi.exec().then((rs) => {
return user;
});
};

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ module.exports = {
};
}
if (session?.users?.id) {
const user = await getProfileId(session);
const user = await getProfileId(session?.users.id);
return {
status: 200,
success: true,
Expand Down
Binary file modified dump.rdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const Login_Users = () => {
useEffect(() => {
if (auth && auth.status === 200) {
STORAGES.saveLocalStorage("Login_Users", true);
if (location.state?.from) {
navigate(location.state.from);
window.location.reload();
} else {
window.location.href = "/";
}
// if (location.state?.from) {
// navigate(location.state.from);
// window.location.reload();
// } else {
window.location.href = "/";
// }
}
if (error) {
toast.error(error.msg);
Expand Down

0 comments on commit fccd930

Please sign in to comment.