Skip to content

Commit

Permalink
write Plan services
Browse files Browse the repository at this point in the history
  • Loading branch information
yash22arora committed Jun 21, 2024
1 parent 97ed67f commit fad592d
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/src/api/routes/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ router.post(
message: err,
});
}
} else {
res.status(400).json({
message: "Invalid Signature",
});
}
}
);
Expand Down
74 changes: 74 additions & 0 deletions server/src/api/services/plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import mongoose from "mongoose";
import { IPlan, Plan } from "../models/plan";
import { TPlanStatus } from "../../utils/types";

export const planService = {
createPlan: async (plan: IPlan) => {
try {
const newPlan = new Plan({
...plan,
_id: new mongoose.Types.ObjectId(),
status: "processing",
hasTxtRecord: false,
expiry: new Date(),
});
const result = await newPlan.save();
return result;
} catch (err) {
console.log(err);
return err;
}
},

getPlanByID: async (id: string) => {
try {
const plan = await Plan.findById(id);
return plan;
} catch (err) {
console.log(err);
return err;
}
},

activePlan: async (razorpaySubscriptionID: string, expiry: Date) => {
try {
const plan = await Plan.findOneAndUpdate(
{ razorpaySubscriptionID },
{ status: "active", expiry }
);
return plan;
} catch (err) {
console.log(err);
return err;
}
},

deletePlan: async () => {
// delete a plan
},

updatePlanStatus: async (planID: string, status: TPlanStatus) => {
// update a plan
try {
const plan = await Plan.findByIdAndUpdate(planID, { status });
} catch (err) {
console.log(err);
return err;
}
},

getPlansByUser: async (userID: string) => {
// get all plans by user
try {
const plans = await Plan.find({ ownerID: userID });
return plans;
} catch (err) {
console.log(err);
return err;
}
},

getPlansByDomain: async () => {
// get all plans by domain
},
};
31 changes: 31 additions & 0 deletions server/src/api/services/record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// create a record

export const recordService = {
createRecord: async () => {
// create a record
},
getRecord: async () => {
// get a record
},
deleteRecord: async () => {
// delete a record
},
updateRecord: async () => {
// update a record
},
getRecordsByUser: async () => {
// get all records by user
},
getRecordsByPlan: async () => {
// get all records by plan
},
getReservedRecord: async () => {
// get a reserved record
},
deleteReservedRecord: async () => {
// delete a reserved record
},
getReservedRecords: async () => {
// get all reserved records
},
};

0 comments on commit fad592d

Please sign in to comment.