validation.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. module.exports.logindatacheck = async function (req, res) {
  2. if (req.body.username == "" || req.body.username == undefined || req.body.username == null) {
  3. return { status: false, data: {}, errors: "Please enter Username" }
  4. }
  5. if (req.body.password == "" || req.body.password == undefined || req.body.password == null) {
  6. return { status: false, data: {}, errors: "Please enter Password" }
  7. }
  8. return { status: true };
  9. }
  10. module.exports.createContactentrycheck = async function (req, res) {
  11. if (req.body.contact_for == "" || req.body.contact_for == undefined || req.body.contact_for == null) {
  12. return { status: false, data: [], errors: "Please enter Customer ID of contact" }
  13. }
  14. if (req.body.first_name == "" || req.body.first_name == undefined || req.body.first_name == null) {
  15. return { status: false, data: [], errors: "Please enter First Name" }
  16. }
  17. if (req.body.last_name == "" || req.body.last_name == undefined || req.body.last_name == null) {
  18. return { status: false, data: [], errors: "Please enter Last Name" }
  19. }
  20. if (req.body.mobile_no == "" || req.body.mobile_no == undefined || req.body.mobile_no == null) {
  21. return { status: false, data: [], errors: "Please enter Mobile No." }
  22. }
  23. if(req.body.mobile_no !=null && req.body.mobile_no !=""){
  24. if(req.body.mobile_no.length != 10 ){
  25. return { status: false, data: [], errors: "Please enter valid Mobile No" }
  26. }
  27. }
  28. // console.log("req.body.email_id",req.body.email_id);
  29. // console.log("req.body.mobile_no",req.body.mobile_no);
  30. if (req.body.email_id == "" || req.body.email_id == undefined || req.body.email_id == null) {
  31. return { status: false, data: [], errors: "Please enter Email ID." }
  32. }
  33. if(req.body.email_id != null && req.body.email_id != ""){
  34. console.log("check valid email");
  35. if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(req.body.email_id)){
  36. console.log("valid email");
  37. }else{
  38. console.log("in vliad email");
  39. return { status: false, data: [], errors: "Please enter valid Email ID" }
  40. }
  41. }
  42. if (req.body.department == "" || req.body.department == undefined || req.body.department == null) {
  43. return { status: false, data: [], errors: "Please enter Department" }
  44. }
  45. if (req.body.function == "" || req.body.function == undefined || req.body.function == null) {
  46. return { status: false, data: [], errors: "Please enter Functional Area" }
  47. }
  48. if (req.body.created_by == "" || req.body.created_by == undefined || req.body.created_by == null) {
  49. return { status: false, data: [], errors: "Please enter Login ID" }
  50. }
  51. return { status: true };
  52. }
  53. module.exports.getdvrDetailscheck = async (req, res) => {
  54. if (req.query.dvrid == "" || req.query.dvrid == undefined || req.query.dvrid == null) {
  55. return { status: false, data: {}, errors: "Please enter DVR ID" }
  56. }
  57. return { status: true };
  58. }
  59. module.exports.createDvrentrycheck = async function (req, res) {
  60. if (req.body.visit_date == "" || req.body.visit_date == undefined || req.body.visit_date == null) {
  61. return { status: false, data: [], errors: "Please enter Date of visit" }
  62. }
  63. if (req.body.customer_name == "" || req.body.customer_name == undefined || req.body.customer_name == null) {
  64. return { status: false, data: [], errors: "Please enter Customer Name" }
  65. }
  66. if (!containsOnlyLetters(req.body.customer_name)) {
  67. return { status: false, data: [], errors: " Please Enter Valid Customer Name " }
  68. }
  69. if (req.body.contact_name == "" || req.body.contact_name == undefined || req.body.contact_name == null) {
  70. return { status: false, data: [], errors: "Please enter Contact Name" }
  71. }
  72. if (req.body.message == "" || req.body.message == undefined || req.body.message == null) {
  73. return { status: false, data: [], errors: "Please enter Meassage" }
  74. }
  75. if (req.body.physical_metting == "" || req.body.physical_metting == undefined || req.body.physical_metting == null) {
  76. return { status: false, data: [], errors: "Please enter Designation" }
  77. }
  78. if (req.body.stage_id == "" || req.body.stage_id == undefined || req.body.stage_id == null) {
  79. return { status: false, data: [], errors: "Please choose Status " }
  80. }
  81. if (req.body.created_by == "" || req.body.created_by == undefined || req.body.created_by == null) {
  82. return { status: false, data: [], errors: "Please enter Login ID" }
  83. }
  84. // if (req.body.sale_person == "" || req.body.sale_person == undefined || req.body.sale_person == null) {
  85. // return { status: false, data: [], errors: "Please enter Login ID" }
  86. // }
  87. // if (req.body.second_contact == "" || req.body.second_contact == undefined || req.body.second_contact == null) {
  88. // return { status: false, data: [], errors: "Please enter Login ID" }
  89. // }
  90. // if (req.body.nextstep == "" || req.body.nextstep == undefined || req.body.nextstep == null) {
  91. // return { status: false, data: [], errors: "Please enter Login ID" }
  92. // }
  93. // if (req.body.objective == "" || req.body.objective == undefined || req.body.objective == null) {
  94. // return { status: false, data: [], errors: "Please enter Login ID" }
  95. // }
  96. // if (req.body.est_Date == "" || req.body.est_Date == undefined || req.body.est_Date == null) {
  97. // return { status: false, data: [], errors: "Please enter Login ID" }
  98. // }
  99. // if (req.body.estvalue == "" || req.body.estvalue == undefined || req.body.estvalue == null) {
  100. // return { status: false, data: [], errors: "Please enter Login ID" }
  101. // }
  102. return { status: true };
  103. }
  104. module.exports.updatedvrDetailscheck = async (req, res) => {
  105. if (req.body.dvr_id == "" || req.body.dvr_id == undefined || req.body.dvr_id == null) {
  106. return { status: false, data: [], errors: "Please enter DVR ID" }
  107. }
  108. if (req.body.visit_date == "" || req.body.visit_date == undefined || req.body.visit_date == null) {
  109. return { status: false, data: [], errors: "Please enter Date of visit" }
  110. }
  111. if (req.body.customer_name == "" || req.body.customer_name == undefined || req.body.customer_name == null) {
  112. return { status: false, data: [], errors: "Please enter Customer Name" }
  113. }
  114. if (req.body.contact_name == "" || req.body.contact_name == undefined || req.body.contact_name == null) {
  115. return { status: false, data: [], errors: "Please enter Contact Name" }
  116. }
  117. if (req.body.message == "" || req.body.message == undefined || req.body.message == null) {
  118. return { status: false, data: {}, errors: "Please enter Mesasge" }
  119. }
  120. if (req.body.physical_metting == "" || req.body.physical_metting == undefined || req.body.physical_metting == null) {
  121. return { status: false, data: {}, errors: "Please enter Physical Metting status" }
  122. }
  123. if (req.body.stage_id == "" || req.body.stage_id == undefined || req.body.stage_id == null) {
  124. return { status: false, data: {}, errors: "Please choose Status" }
  125. }
  126. if (req.body.updated_by == "" || req.body.updated_by == undefined || req.body.updated_by == null) {
  127. return { status: false, data: {}, errors: "Please enter Login ID for updation." }
  128. }
  129. return { status: true };
  130. }
  131. module.exports.signupCheck = async function (req, res) {
  132. if (req.body.login_id == "" || req.body.login_id == undefined || req.body.login_id == null) {
  133. return { status: false, data: {}, errors: "Please enter Login Id" }
  134. }
  135. if (req.body.customer_id == "" || req.body.customer_id == undefined || req.body.customer_id == null) {
  136. return { status: false, data: {}, errors: "Please enter Customer Id" }
  137. }
  138. if (req.body.password == "" || req.body.password == undefined || req.body.password == null) {
  139. return { status: false, data: {}, errors: "Please enter Password" }
  140. }
  141. // if (req.body.password.length != '8'){
  142. // return { status: false, data: {}, errors: "Please enter 8 digits Password" }
  143. // }
  144. if (req.body.first_name == "" || req.body.first_name == undefined || req.body.first_name == null) {
  145. return { status: false, data: {}, errors: "Please enter First Name" }
  146. }
  147. if (req.body.last_name == "" || req.body.last_name == undefined || req.body.last_name == null) {
  148. return { status: false, data: {}, errors: "Please enter Last Name" }
  149. }
  150. if (req.body.email == "" || req.body.email == undefined || req.body.email == null) {
  151. return { status: false, data: {}, errors: "Please enter Email" }
  152. }
  153. if (req.body.mobile_number == "" || req.body.mobile_number == undefined || req.body.mobile_number == null) {
  154. return { status: false, data: {}, errors: "Please enter Mobile Number" }
  155. }
  156. if (req.body.mobile_number.length != '10') {
  157. return { status: false, data: {}, errors: "Please Enter 10 digit Mobile Number" }
  158. }
  159. return { status: true };
  160. }
  161. module.exports.userrolemapcheck = async function (req, res) {
  162. if (req.body.login_id == "" || req.body.login_id == undefined || req.body.login_id == null) {
  163. return { status: false, data: {}, errors: "Please enter login id" }
  164. }
  165. if (req.body.user_role_id == "" || req.body.user_role_id == undefined || req.body.user_role_id == null) {
  166. return { status: false, data: {}, errors: "Please enter user role id" }
  167. }
  168. return { status: true };
  169. }
  170. module.exports.createCustomerentrycheck = async function (req, res) {
  171. if (req.body.customer_name == "" || req.body.customer_name == undefined || req.body.customer_name == null) {
  172. return { status: false, data: {}, errors: "Please enter Valid Customer Name" }
  173. }
  174. if (!containsOnlyLetters(req.body.customer_name)) {
  175. return { status: false, data: {}, errors: "Please enter Valid Customer Name" }
  176. }
  177. if (req.body.sale_person == "" || req.body.sale_person == undefined || req.body.sale_person == null) {
  178. return { status: false, data: {}, errors: "Please enter Valid Sales Person Name" }
  179. }
  180. if (req.body.created_by == "" || req.body.created_by == undefined || req.body.created_by == null) {
  181. return { status: false, data: {}, errors: "Please enter Login ID" }
  182. }
  183. return { status: true };
  184. }
  185. module.exports.updateContactDetailscheck = async (req, res) => {
  186. var validRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
  187. if (req.body.contact_id == "" || req.body.contact_id == undefined || req.body.contact_id == null) {
  188. return { status: false, data: {}, errors: "Please enter contact Id" }
  189. }
  190. if (req.body.customer_id == "" || req.body.customer_id == undefined || req.body.customer_id == null) {
  191. return { status: false, data: {}, errors: "Please enter Customer Id" }
  192. }
  193. if (req.body.first_name == "" || req.body.first_name == undefined || req.body.first_name == null) {
  194. return { status: false, data: {}, errors: "Please enter First Name" }
  195. }
  196. if (req.body.last_name == "" || req.body.last_name == undefined || req.body.last_name == null) {
  197. return { status: false, data: {}, errors: "Please enter Last Name" }
  198. }
  199. if (req.body.mobile_number == "" || req.body.mobile_number == undefined || req.body.mobile_number == null) {
  200. return { status: false, data: {}, errors: "Please enter Mobile Number" }
  201. }
  202. if (req.body.mobile_number.length != '10') {
  203. return { status: false, data: {}, errors: "Please enter 10 digits Mobile Number" }
  204. }
  205. if (req.body.email_id == "" || req.body.email_id == undefined || req.body.email_id == null) {
  206. console.log("req.body.email_id", req.body.email_id);
  207. return { status: false, data: {}, errors: "Please enter Email Id" }
  208. }
  209. // console.log("req.body.email_id",req.body.email_id);
  210. //console.log("check validation",req.body.email_id.match(validRegex));
  211. // if(req.body.email_id.match(validRegex) == false){
  212. // return { status: false, data: {}, errors: "Please enter valid Email ID" }
  213. // }
  214. if (req.body.designation == "" || req.body.designation == undefined || req.body.designation == null) {
  215. return { status: false, data: {}, errors: "Please enter Designation" }
  216. }
  217. if (req.body.department == "" || req.body.department == undefined || req.body.department == null) {
  218. return { status: false, data: {}, errors: "Please enter Department" }
  219. }
  220. if (req.body.updated_by == "" || req.body.updated_by == undefined || req.body.updated_by == null) {
  221. return { status: false, data: {}, errors: "Please enter Login ID for updation " }
  222. }
  223. return { status: true };
  224. }
  225. module.exports.updateCustomerDetailscheck = async (req, res) => {
  226. if (req.body.customer_id == "" || req.body.customer_id == undefined || req.body.customer_id == null) {
  227. return { status: false, data: {}, errors: "Please enter contact Id" }
  228. }
  229. if (req.body.customer_name == "" || req.body.customer_name == undefined || req.body.customer_name == null) {
  230. return { status: false, data: {}, errors: "Please enter Customer Name" }
  231. }
  232. if (!containsOnlyLetters(req.body.customer_name)) {
  233. return { status: false, data: {}, errors: " Please Enter Valid Customer Name ." }
  234. }
  235. if (req.body.updated_by == "" || req.body.updated_by == undefined || req.body.updated_by == null) {
  236. return { status: false, data: {}, errors: "Please enter Login ID for updation " }
  237. }
  238. return { status: true };
  239. }
  240. module.exports.mappingCustomerDetailsCheck = async (req, res) => {
  241. if (req.query.sale_person == "" || req.query.sale_person == undefined || req.query.sale_person == null) {
  242. return { status: false, data: {}, errors: "Please enter sale person" }
  243. }
  244. return { status: true };
  245. }
  246. module.exports.mappingFuncIDToPersonNamesCheck = async (req, res) => {
  247. if (req.query.func_id == "" || req.query.func_id == undefined || req.query.func_id == null) {
  248. return { status: false, data: {}, errors: "Please enter func id" }
  249. }
  250. return { status: true };
  251. }
  252. function containsOnlyLetters(str) {
  253. //return /^[A-Za-z\s]+$/.test(str);
  254. return /^[ A-Za-z_@./#&+-]*$/.test(str);
  255. }