Guest User

Untitled

a guest
Feb 7th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. const bankAccSchema = new Schema({
  2. user: {
  3. type: Schema.Types.ObjectId,
  4. ref: "user"
  5. },
  6. name: {
  7. type: String,
  8. required: [true, "Bank Name is Required"]
  9. },
  10. acc_number: {
  11. type: Number,
  12. required: [true, "Bank Acc Number is Required"]
  13. },
  14. acc_type: {
  15. type: String,
  16. enum: validTypes,
  17. required: [true, "Bank Acc Number is Required"]
  18. },
  19. country: {
  20. type: String //Venezuela
  21. },
  22. country_id: {
  23. type: String //VE
  24. },
  25. created_at: {
  26. type: Date,
  27. default: new Date()
  28. },
  29. updated_at: Date,
  30. deleted_at: Date,
  31. deleted: {
  32. type: Boolean,
  33. default: false
  34. }
  35. });
  36.  
  37.  
  38. const chatSchema = new Schema({
  39. transaction: {
  40. type: Schema.Types.ObjectId,
  41. ref: "transaction"
  42. },
  43. messages: [
  44. {
  45. type: Schema.Types.ObjectId,
  46. ref: "message"
  47. }
  48. ],
  49. secure_hash: String,
  50. created_at: { type: Date, default: new Date() },
  51. updated_at: Date,
  52. deleted_at: Date,
  53. deleted: { type: Boolean, default: false }
  54. });
  55.  
  56. const countrySchema = new Schema({
  57. iso_code: String,
  58. country: String,
  59. currency: {
  60. iso_code: String,
  61. iso_symbol: String,
  62. name: String
  63. },
  64. created_at: {
  65. type: Date,
  66. default: new Date()
  67. },
  68. updated_at: Date,
  69. deleted_at: Date,
  70. deleted: {
  71. type: Boolean,
  72. default: false
  73. }
  74. });
  75.  
  76. const groupSchema = new Schema({
  77. title: String,
  78. wallet: {
  79. type: Schema.Types.ObjectId,
  80. ref: "wallet"
  81. },
  82. owners: [
  83. {
  84. type: Schema.Types.ObjectId,
  85. ref: "user"
  86. }
  87. ],
  88. members: [
  89. {
  90. type: Schema.Types.ObjectId,
  91. ref: "user"
  92. }
  93. ],
  94. created_at: { type: Date, default: new Date() },
  95. updated_at: Date,
  96. deleted_at: Date,
  97. deleted: { type: Boolean, default: false }
  98. });
  99.  
  100. const messageSchema = new Schema({
  101. chat: {
  102. type: Schema.Types.ObjectId,
  103. ref: "chat"
  104. },
  105. sender: {
  106. type: Schema.Types.ObjectId,
  107. ref: "user"
  108. },
  109. receiver: {
  110. type: Schema.Types.ObjectId,
  111. ref: "user"
  112. },
  113. content: String,
  114. type_file: {
  115. type: String,
  116. enum: validTypes
  117. },
  118. attached: String,
  119. has_attached: { type: Boolean, default: false },
  120. status: {
  121. type: String,
  122. default: "sending",
  123. enum: validStatus
  124. },
  125. secure_hash: String,
  126. created_at: { type: Date, default: new Date() },
  127. updated_at: Date,
  128. deleted_at: Date,
  129. deleted: { type: Boolean, default: false }
  130. });
  131.  
  132. const notificationSchema = new Schema({
  133. sender: {
  134. type: Schema.Types.ObjectId,
  135. ref: "user"
  136. },
  137. receiver: {
  138. type: Schema.Types.ObjectId,
  139. ref: "user"
  140. },
  141. title: {
  142. type: String,
  143. required: [true, "Title for notification is Required"]
  144. },
  145. message: {
  146. type: String,
  147. required: [true, "Message is Required"]
  148. },
  149. link: {
  150. type: String
  151. /**
  152. * Link para llevarlo directo a la transaccion o a la noticia que se este transmitiendo
  153. */
  154. },
  155. read: {
  156. type: Boolean,
  157. default: false
  158. },
  159. created_at: {
  160. type: Date,
  161. default: new Date()
  162. },
  163. updated_at: Date,
  164. deleted_at: Date,
  165. deleted: {
  166. type: Boolean,
  167. default: false
  168. }
  169. });
  170.  
  171. const profileSchema = new Schema({
  172. first_name: String,
  173. last_name: String,
  174. full_name: String,
  175. birthday: Date,
  176. address_1: String,
  177. address_2: String,
  178. dni: String,
  179. zip_code: {
  180. type: String,
  181. validate: {
  182. validator: v => {
  183. return /^[0-9]{4,5}(?:-[0-9]{4})?$/g.test(v);
  184. },
  185. message: () => `Invalid Zip-Code`
  186. }
  187. },
  188. phone_1: Number,
  189. phone_2: Number,
  190. country: String,
  191. country_id: String, // ex: VE
  192. created_at: { type: Date, default: new Date() },
  193. updated_at: Date,
  194. deleted_at: Date,
  195. deleted: Boolean,
  196. user: {
  197. type: Schema.Types.ObjectId,
  198. ref: "user"
  199. }
  200. });
  201.  
  202. const referralSchema = new Schema({
  203. by: { type: Schema.Types.ObjectId, ref: "user" },
  204. user: { type: Schema.Types.ObjectId, ref: "user" },
  205. status: { type: String, default: "uncompleted", enum: status }, // True = Completo la condicion para que ambos tengan el reward
  206. created_at: { type: Date, default: new Date() },
  207. updated_at: Date,
  208. deleted_at: Date,
  209. deleted: { type: Boolean, default: false }
  210. });
  211.  
  212. const ticketSchema = new Schema({
  213. user: {
  214. type: Schema.Types.ObjectId,
  215. ref: "user"
  216. },
  217. agent: {
  218. type: Schema.Types.ObjectId,
  219. ref: "user"
  220. },
  221. status: {
  222. type: String,
  223. default: "pending",
  224. enum: validStatus
  225. },
  226. issue: String,
  227. category: {
  228. type: String,
  229. enum: validCategories
  230. },
  231. created_at: { type: Date, default: new Date() },
  232. updated_at: Date,
  233. deleted_at: Date,
  234. deleted: { type: Boolean, default: false }
  235. });
  236.  
  237. const validStatus = {
  238. values: ["pending", "accepted", "confirmed", "completed", "cancelled", "expired"],
  239. message: `{VALUE} is not a valid status`
  240. };
  241.  
  242. const validPaymentMethods = {
  243. values: [
  244. "e_tranfer",
  245. "bank_tranfer",
  246. "cash",
  247. "cryptocurrency",
  248. "gift_card",
  249. "mobile"
  250. ],
  251. message: `{VALUE} is not a valid payment method`
  252. };
  253.  
  254. const validTypes = {
  255. values: ["withdraw", "deposit", "tranfer", "send", "received"],
  256. message: `{VALUE} is not a valid payment method`
  257. };
  258.  
  259. const transactionSchema = new Schema({
  260. sender: {
  261. type: Schema.Types.ObjectId, // seller
  262. ref: "user"
  263. },
  264. receiver: {
  265. type: Schema.Types.ObjectId, // buyer
  266. ref: "user"
  267. },
  268. chat: {
  269. type: Schema.Types.ObjectId,
  270. ref: "chat"
  271. },
  272. balance: Number,
  273. location: String, // Country -> Venezuela
  274. flag: String, // country_id -> VE
  275. status: {
  276. type: String,
  277. enum: validStatus,
  278. default: "pending"
  279. },
  280. amount: Number,
  281. fee: Number,
  282. local_currency: String,
  283. exchange_currency: { type: String, default: 'KlippUSD'},
  284. pair: String, // this.local_currency:this.exchange_currency --- KlippUSD/BsS or BsS/KlippUSD
  285. payment_method: {
  286. type: String,
  287. enum: validPaymentMethods
  288. },
  289. exchange_rate: Number, // ex: 345 BsS -> 1$ === 345 BsS
  290. typo: {
  291. type: String,
  292. enum: validTypes
  293. },
  294. created_at: { type: Date, default: new Date() },
  295. updated_at: Date,
  296. deleted_at: Date,
  297. deleted: { type: Boolean, default: false }
  298. });
  299.  
  300. const UserSchema = new Schema({
  301. email: {
  302. type: String,
  303. required: [true, "Email is required"],
  304. validate: {
  305. validator: function(value) {
  306. return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(
  307. value
  308. );
  309. },
  310. message: () => `Invalid Email`
  311. },
  312. unique: true
  313. },
  314. password: {
  315. type: String,
  316. required: [true, "Password is required"],
  317. validate: {
  318. validator: function(value) {
  319. return /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%.^&/*-]).{6,}$/.test(
  320. value
  321. );
  322. },
  323. message: () => `Invalid Password`
  324. /*
  325. TODO: put this message in the front-end
  326.  
  327. At least one upper case English letter, (?=.*?[A-Z])
  328. At least one lower case English letter, (?=.*?[a-z])
  329. Non ñ-Ñ
  330. At least one digit, (?=.*?[0-9])
  331. At least one special character, (?=.*?[#?!@$%^&*-])
  332. Minimum six in length .{6,} (with the anchors)
  333. */
  334. }
  335. },
  336. user_agent: {
  337. ip: String,
  338. country_id: String, // VE,
  339. country: String, // VENEZUELA,
  340. browser: String,
  341. },
  342. access_token: String,
  343. validate_link: String,
  344. recover_code: String,
  345. validated: { type: Boolean, default: false },
  346. show_email: { type: Boolean, default: true },
  347. language: { type: String, default: "en" }, // EN/ES
  348. rate: { type: Number, default: 0 }, // [0 a 10]
  349. created_at: { type: Date, default: new Date() },
  350. updated_at: Date,
  351. deleted_at: Date,
  352. last_enter: Date,
  353. deleted: { type: Boolean, default: false },
  354. role: {
  355. type: String,
  356. default: "regular",
  357. enum: roles
  358. },
  359. currency: { type: String, default: "Klipp-USD" },
  360. status: {
  361. type: String,
  362. default: "active",
  363. enum: status
  364. },
  365. verified: { type: Boolean, default: false }, // All fields verified
  366. verified_email: { type: Boolean, default: false }, // Verified email
  367. verified_docs: { type: Boolean, default: false }, // Verified Document -- DNI || Passport || drive licence
  368. documents: {
  369. dni: String, // path image
  370. passport: String, // path image
  371. drive_lic: String, // path image
  372. face_photo: String // path image
  373. },
  374. profile: {
  375. type: Schema.Types.ObjectId,
  376. ref: "profile"
  377. },
  378. referral_code: { type: String },
  379. referrals: [
  380. {
  381. type: Schema.Types.ObjectId,
  382. ref: "referral"
  383. }
  384. ],
  385. wallets: [
  386. {
  387. type: Schema.Types.ObjectId,
  388. ref: "wallet"
  389. }
  390. ],
  391. groups: [
  392. {
  393. type: Schema.Types.ObjectId,
  394. ref: "group"
  395. }
  396. ],
  397. transactions: [
  398. {
  399. type: Schema.Types.ObjectId,
  400. ref: "transaction"
  401. }
  402. ],
  403. tickets: [
  404. {
  405. type: Schema.Types.ObjectId,
  406. ref: "ticket"
  407. }
  408. ],
  409. bank_accounts: [
  410. {
  411. type: Schema.Types.ObjectId,
  412. ref: "bankAccount"
  413. }
  414. ]
  415. });
  416.  
  417. const walletSchema = new Schema({
  418. user: {
  419. type: Schema.Types.ObjectId,
  420. ref: "user"
  421. },
  422. group: {
  423. type: Schema.Types.ObjectId,
  424. ref: "group"
  425. },
  426. address: String,
  427. currency: String, // USD === KlippUSD
  428. symbol: String, // USD - K-USD - Klipps
  429. balance: { type: Number, default: 0.0 },
  430. wallet_type: {
  431. type: String,
  432. enum: validTypes
  433. },
  434. created_at: { type: Date, default: new Date() },
  435. updated_at: Date,
  436. deleted_at: Date,
  437. deleted: { type: Boolean, default: false }
  438. });
Add Comment
Please, Sign In to add comment