-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97ed67f
commit fad592d
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}; |