This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(search): user search for a request
- add the search controller - add test for the search functionality - add the validation rule middleware - document the search feature [Maintains #170947564]
- Loading branch information
Showing
21 changed files
with
338 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
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
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
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
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,41 @@ | ||
import { Sequelize } from 'sequelize'; | ||
import db from '../models'; | ||
import stringHelper from '../utils/stringHelper'; | ||
|
||
const { Op } = Sequelize; | ||
/** | ||
* @class TripsService | ||
* @description this class handles trips services | ||
*/ | ||
export default class TripsService { | ||
/** | ||
* set the user token and send the email(servicee) | ||
* @param {object} obj | ||
* @param {object} user | ||
* @returns {object} request array | ||
*/ | ||
static async searchRequest(obj, user) { | ||
const searchObj = {}; | ||
searchObj.where = {}; | ||
let field = { ...obj }; | ||
field = JSON.parse(JSON.stringify(field)); | ||
const fieldArr = Object.keys(field); | ||
if (user.role === 'requester') { | ||
searchObj.where.email = user.email; | ||
} | ||
if (user.role === 'manager') { | ||
searchObj.where.managerId = user.id; | ||
} | ||
fieldArr.forEach((el) => { | ||
searchObj.where[el] = obj[el]; | ||
if (el === 'location' || el === 'departure' || el === 'status' || el === 'accommodation' || el === 'reason' || el === 'destination') { | ||
searchObj.where[el] = { [Op.iLike]: `%${field[el].trim()}%` }; | ||
} | ||
}); | ||
const requests = await db.Request.findAll(searchObj); | ||
if (requests.length < 1) { | ||
return stringHelper.requestNotFound; | ||
} | ||
return requests; | ||
} | ||
} |
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
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
Oops, something went wrong.