-
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
Gutierrez, Andres
committed
Apr 30, 2021
1 parent
73fefce
commit bb1606a
Showing
1 changed file
with
31 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { dbc, ObjectId, withErrorHandler, logger } from "../../infrastructure"; | ||
|
||
const searchAllApis = async (limit = null, next = 0) => { | ||
logger.debug(`Calling to db -> get all responses`); | ||
if (limit !== null) { | ||
return await dbc.apis.find({}) | ||
.skip(next) | ||
.limit(limit) | ||
.toArray(); | ||
} | ||
return await dbc.apis.find({}).toArray(); | ||
}; | ||
|
||
const searchAnApi = async (apiIds) => { | ||
logger.debug(`Calling to db -> Get api: ${apiIds}`); | ||
if (!Array.isArray(apiIds)) { | ||
apiIds = [apiIds]; | ||
} | ||
|
||
const listObjectIds = apiIds.map((id) => ObjectId(id)); | ||
return await dbc.apis.find({ _id: { $in: listObjectIds } }).toArray(); | ||
}; | ||
|
||
const countApis = async () => await dbc.apis.countDocuments({}); | ||
|
||
|
||
export default { | ||
searchAllApis: withErrorHandler(searchAllApis), | ||
searchAnApi: withErrorHandler(searchAnApi), | ||
countApis: withErrorHandler(countApis), | ||
}; | ||
import { dbc, ObjectId, withErrorHandler, logger } from "../../infrastructure"; | ||
|
||
const searchAllApis = async (limit = null, next = 0) => { | ||
logger.debug(`Calling to db -> get all apis`); | ||
if (limit !== null) { | ||
return await dbc.apis.find({}) | ||
.skip(next) | ||
.limit(limit) | ||
.toArray(); | ||
} | ||
return await dbc.apis.find({}).toArray(); | ||
}; | ||
|
||
const searchAnApi = async (apiIds) => { | ||
logger.debug(`Calling to db -> Get api: ${apiIds}`); | ||
if (!Array.isArray(apiIds)) { | ||
apiIds = [apiIds]; | ||
} | ||
|
||
const listObjectIds = apiIds.map((id) => ObjectId(id)); | ||
return await dbc.apis.find({ _id: { $in: listObjectIds } }).toArray(); | ||
}; | ||
|
||
const countApis = async () => await dbc.apis.countDocuments({}); | ||
|
||
|
||
export default { | ||
searchAllApis: withErrorHandler(searchAllApis), | ||
searchAnApi: withErrorHandler(searchAnApi), | ||
countApis: withErrorHandler(countApis), | ||
}; |