Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find reminder by ID #318

Merged
merged 9 commits into from
Sep 3, 2021
6 changes: 3 additions & 3 deletions src/config/environment/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
Copyright 2021, Zuri plugin reminder.
All rights reserved.
Written By: King Etiosasere, 30th August 2021
Copyright 2021, Zuri plugin reminder.
All rights reserved.
Written By: King Etiosasere, 30th August 2021
* */
import dotenv from 'dotenv'

Expand Down
15 changes: 14 additions & 1 deletion src/db/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios'

import env from '@config/environment'
import { get } from 'mongoose'

const { getDevBaseUrl, ORG_ID, PLUGIN_ID } = env

Expand All @@ -23,5 +24,17 @@ export default function makeDb() {
return data
}

return Object.freeze({ findAll })
async function findById(collectionName, id) {
// findById function that interacts with the database endpoint
try {
const res = await axios({
url: `${readBaseUrl}/${PLUGIN_ID}/${collectionName}/${ORG_ID}?id=${id}`,
method: get,
})
return res.data.data
} catch (error) {
return error.response.data
}
}
return Object.freeze({ findAll, findById })
}