coupon and affiliate
This commit is contained in:
parent
5ee536700a
commit
7efc94cbc6
@ -2,16 +2,68 @@ import axios from "axios";
|
||||
import { AffiliateModel } from "./AffiliateModel.js";
|
||||
|
||||
import Razorpay from "razorpay";
|
||||
import UserModel from "../../user/userModel.js";
|
||||
const razorpay = new Razorpay({
|
||||
key_id: process.env.RAZERPAY_KEY_ID,
|
||||
key_secret: process.env.RAZERPAY_SECRET_KEY,
|
||||
});
|
||||
import password from "secure-random-password";
|
||||
import sendEmail from "../../../Utils/sendEmail.js";
|
||||
|
||||
// -----------------------------AFFILIATE & COUPONS ARE HARDLY BINDED DATA--------------------------------------------------------
|
||||
//Create Affiliate
|
||||
export const createAffiliate = async (req, res) => {
|
||||
try {
|
||||
const result = req.body;
|
||||
let findAffiliate = await AffiliateModel.findOne({ email: result?.email });
|
||||
if (findAffiliate) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "This Email Id Affiliate Already exists",
|
||||
});
|
||||
}
|
||||
// Check if email already exists in User collection
|
||||
let findUser = await UserModel.findOne({ email: result?.email });
|
||||
if (!findUser) {
|
||||
const passwords = password.randomPassword({
|
||||
length: 10,
|
||||
characters: [
|
||||
{ characters: password.upper, exactly: 1 },
|
||||
{ characters: password.symbols, exactly: 1 },
|
||||
password.lower,
|
||||
password.digits,
|
||||
],
|
||||
});
|
||||
|
||||
// req.body.password = passwords;
|
||||
const user = await UserModel.create({
|
||||
password: passwords,
|
||||
phone: result?.mobile,
|
||||
...result,
|
||||
});
|
||||
// console.log("user", user);
|
||||
await sendEmail({
|
||||
to: `${result?.email}`, // Change to your recipient
|
||||
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
|
||||
subject: `Welcome to Smellika Affiliate!`,
|
||||
html: ` <h1 style="color: #333; text-align: left; font-family: Arial, sans-serif;">Welcome to Smellika Affiliate!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hey ${
|
||||
result?.name
|
||||
},</strong>
|
||||
|
||||
|
||||
<br/>
|
||||
<p style="color: #555; font-size: 15px;">You can login into :${`https://smellika.com`} </p>
|
||||
<br/>
|
||||
<p style="color: #555; font-size: 15px;">Below are your Affiliate login credentials:</p>
|
||||
<p style="color: #555; font-size: 15px;">Email: ${result?.email}</p>
|
||||
<p style="color: #555; font-size: 15px;">Password: ${passwords}</p>
|
||||
<span style="color: #555; font-size: 13px;">Happy shopping,</span><br/>`,
|
||||
});
|
||||
}
|
||||
|
||||
const affiliate = new AffiliateModel(result);
|
||||
const savedData = await affiliate.save();
|
||||
if (savedData) {
|
||||
@ -419,3 +471,35 @@ export const affiliatPayOut = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//LIST ALL AFFILIATE
|
||||
export const MyAllAffiliate = async (req, res) => {
|
||||
try {
|
||||
const user = await UserModel.findById(req.params.id);
|
||||
if (user?.email) {
|
||||
const affiliate = await AffiliateModel.find(
|
||||
{ email: user?.email },
|
||||
{
|
||||
name: 1,
|
||||
_id: 1,
|
||||
email: 1,
|
||||
coupon_claimed: 1,
|
||||
coupon_code: 1,
|
||||
total_earning: 1,
|
||||
paid_amount: 1,
|
||||
// is_affiliate_active: 1,
|
||||
}
|
||||
).sort({ createdAt: -1 });
|
||||
// console.log("affiliate", affiliate);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: affiliate,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
messgae: error.message ? error.message : "Something went wrong!",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
import express from "express";
|
||||
import {
|
||||
MyAllAffiliate,
|
||||
affiliatPayOut,
|
||||
affiliatePayHistory,
|
||||
createAffiliate,
|
||||
@ -30,6 +31,8 @@ router.get(
|
||||
authorizeRoles("admin", "Employee"),
|
||||
listAllAffiliate
|
||||
);
|
||||
router.get("/my/:id", isAuthenticatedUser, MyAllAffiliate);
|
||||
|
||||
router.get(
|
||||
"/getone/:id",
|
||||
isAuthenticatedUser,
|
||||
|
Loading…
Reference in New Issue
Block a user