Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.61 KB | None | 0 0
  1.  
  2. const bcrypt = require('bcrypt');
  3. const seedDatabase = require('../util/seedDatabase');
  4. const uuid = require('uuid').v4;
  5. const moment = require('moment');
  6. // For hashing passwords for User seeds
  7. // TODO: pull fromm global config, cause needs to be reused with deserialization
  8. const saltRounds = 10;
  9.  
  10.  
  11. /**
  12. * Seeds Map is organized by:
  13. *
  14. * {
  15. * [TABLE_NAME1]: [ MODEL1_DATA, ],
  16. * [TABLE_NAME2]: [ MODEL2_DATA, ],
  17. * ...
  18. * }
  19. *
  20. */
  21.  
  22.  
  23. const accountId = uuid();
  24. const justinPatientId = uuid();
  25. const sergeyPatientId = uuid();
  26. const lonnyUserId = uuid();
  27. const justinUserId = uuid();
  28. const markUserId = uuid();
  29. const ashmeetUserId = uuid();
  30. const sergeyUserId = uuid();
  31.  
  32. const alexUserId = uuid();
  33. const alexPatientId = uuid();
  34. const practitionerId = uuid();
  35. const practitionerId2 = uuid();
  36. const chairId = uuid();
  37. const serviceId = uuid();
  38. const serviceId2 = uuid();
  39. const appointmentId1 = uuid();
  40. const appointmentId2 = uuid();
  41.  
  42. const SEEDS = {
  43. Appointment: [
  44. {
  45. startTime: new Date(2017, 1, 13, 9, 0, 0, 0),
  46. endTime: new Date(2017, 1, 13, 17, 0, 0, 0),
  47. title: 'alexPatientId, serviceId2, practitionerId2, Sooner Availability',
  48. id: appointmentId1,
  49. accountId,
  50. patientId: alexPatientId,
  51. serviceId: serviceId2,
  52. practitionerId: practitionerId2,
  53. chairId: chairId,
  54. },
  55.  
  56. {
  57. startTime: new Date(2017, 1, 13, 9, 0, 0, 0),
  58. endTime: new Date(2017, 1, 13, 12, 0, 0, 0),
  59. title: 'alexPatientId, serviceId2, practitionerId, Full day',
  60. id: uuid(),
  61. accountId,
  62. patientId: alexPatientId,
  63. serviceId: serviceId2,
  64. practitionerId: practitionerId,
  65. chairId: chairId,
  66. },
  67.  
  68. {
  69. startTime: new Date(2017, 1, 14, 9, 0, 0, 0),
  70. endTime: new Date(2017, 1, 14, 17, 0, 0, 0),
  71. title: 'alexPatientId, serviceId2, practitionerId2, Sooner Availability',
  72. id: uuid(),
  73. accountId,
  74. patientId: alexPatientId,
  75. serviceId: serviceId2,
  76. practitionerId: practitionerId2,
  77. chairId: chairId,
  78. },
  79.  
  80. {
  81. startTime: new Date(2017, 1, 14, 9, 0, 0, 0),
  82. endTime: new Date(2017, 1, 14, 17, 0, 0, 0),
  83. title: 'alexPatientId, serviceId2, practitionerId, Full day',
  84. id: uuid(),
  85. accountId,
  86. patientId: alexPatientId,
  87. serviceId: serviceId2,
  88. practitionerId: practitionerId,
  89. chairId: chairId,
  90. },
  91.  
  92.  
  93.  
  94. {
  95. startTime: new Date(2017, 1, 15, 9, 0, 0, 0),
  96. endTime: new Date(2017, 1, 15, 12, 0, 0, 0),
  97. title: 'Full day',
  98. id: uuid(),
  99. accountId,
  100. patientId: alexPatientId,
  101. serviceId: serviceId2,
  102. practitionerId: practitionerId,
  103. chairId: chairId,
  104. },
  105.  
  106. {
  107. startTime: new Date(2017, 1, 15, 15, 35, 0, 0),
  108. endTime: new Date(2017, 1, 15, 17, 0, 0, 0),
  109. title: 'Full day',
  110. id: uuid(),
  111. accountId,
  112. patientId: alexPatientId,
  113. serviceId: serviceId2,
  114. practitionerId: practitionerId,
  115. chairId: chairId,
  116. },
  117.  
  118. {
  119. startTime: new Date(2017, 1, 15, 9, 0, 0, 0),
  120. endTime: new Date(2017, 1, 15, 17, 0, 0, 0),
  121. title: '15 full time',
  122. id: uuid(),
  123. accountId,
  124. patientId: alexPatientId,
  125. serviceId: serviceId2,
  126. practitionerId: practitionerId2,
  127. chairId: chairId,
  128. },
  129.  
  130. ],
  131.  
  132. User: [
  133. {
  134. username: 'lonny@carecru.com',
  135. password: bcrypt.hashSync('lonny', saltRounds),
  136. id: lonnyUserId,
  137. activeAccountId: accountId,
  138. // accounts: [accountId],
  139. },
  140. {
  141. username: 'mark@carecru.com',
  142. password: bcrypt.hashSync('mark', saltRounds),
  143. id: markUserId,
  144. activeAccountId: accountId,
  145. // accounts: [accountId],
  146. },
  147. {
  148. username: 'justin@carecru.com',
  149. password: bcrypt.hashSync('justin', saltRounds),
  150. id: justinUserId,
  151. activeAccountId: accountId,
  152. // accounts: [accountId],
  153. },
  154. {
  155. username: 'ashmeet@carecru.com',
  156. password: bcrypt.hashSync('ashmeet', saltRounds),
  157. id: ashmeetUserId,
  158. activeAccountId: accountId,
  159. // accounts: [accountId],
  160. },
  161. {
  162. username: 'sergey@carecru.com',
  163. password: bcrypt.hashSync('sergey', saltRounds),
  164. id: sergeyUserId,
  165. activeAccountId: accountId,
  166. // accounts: [accountId],
  167. },
  168. {
  169. username: 'alex@carecru.com',
  170. password: bcrypt.hashSync('alex', saltRounds),
  171. id: alexUserId,
  172. activeAccountId: accountId,
  173. },
  174. ],
  175.  
  176. Patient: [
  177. {
  178. firstName: 'Justin',
  179. lastName: 'Sharp',
  180. phoneNumber: '+17808508886',
  181. id: justinPatientId,
  182. },
  183. {
  184. firstName: 'Sergey',
  185. lastName: 'Skovorodnikov',
  186. phoneNumber: '+17782422626',
  187. id: sergeyPatientId,
  188. },
  189. {
  190. firstName: 'Mark',
  191. lastName: 'Joseph',
  192. phoneNumber: '+17788654451',
  193. id: uuid(),
  194. },
  195. {
  196. firstName: 'Alex',
  197. lastName: 'Bashliy',
  198. phoneNumber: '+19782521845',
  199. id: alexPatientId,
  200. email: 'alex.bashliy@keenethics.com',
  201. appointmentPreference: 'both',
  202. },
  203. ],
  204.  
  205. Account: [
  206. {
  207. name: 'Beckett Dental',
  208. vendastaId: 'UNIQUE_CUSTOMER_IDENTIFIER',
  209. smsPhoneNumber: '+17786558613',
  210. id: accountId,
  211. },
  212. ],
  213.  
  214. Permission: [
  215. {
  216. id: uuid(),
  217. userId: lonnyUserId,
  218. accountId,
  219. role: 'OWNER',
  220. permissions: { reviews: { create: true } }, // test permission
  221. },
  222. {
  223. id: uuid(),
  224. userId: justinUserId,
  225. accountId,
  226. role: 'OWNER',
  227. permissions: {},
  228. },
  229. {
  230. id: uuid(),
  231. userId: ashmeetUserId,
  232. accountId,
  233. role: 'OWNER',
  234. permissions: {},
  235. },
  236. {
  237. id: uuid(),
  238. userId: markUserId,
  239. accountId,
  240. role: 'OWNER',
  241. permissions: {},
  242. },
  243. {
  244. id: uuid(),
  245. userId: sergeyUserId,
  246. accountId,
  247. role: 'VIEWER',
  248. permissions: {},
  249. },
  250. ],
  251.  
  252. Service: [
  253. {
  254. id: serviceId,
  255. accountId: accountId,
  256. name: 'Routine Checkup',
  257. practitioners: [practitionerId],
  258. duration: 30,
  259. bufferTime: 0,
  260. unitCost: 40,
  261. customCosts: {},
  262. },
  263. {
  264. id: serviceId2,
  265. accountId: accountId,
  266. name: 'Another service',
  267. practitioners: [practitionerId2],
  268. duration: 30,
  269. bufferTime: 0,
  270. unitCost: 40,
  271. customCosts: {},
  272. },
  273. {
  274. id: uuid(),
  275. accountId: accountId,
  276. name: 'third service',
  277. practitioners: [practitionerId2],
  278. duration: 50,
  279. bufferTime: 0,
  280. unitCost: 40,
  281. customCosts: {},
  282. },
  283. ],
  284.  
  285. Practitioner: [
  286. {
  287. id: practitionerId,
  288. accountId: accountId,
  289. firstName: 'Chelsea',
  290. lastName: 'Mansfield',
  291. },
  292. {
  293. id: practitionerId2,
  294. accountId,
  295. firstName: 'Perry',
  296. lastName: 'Cox',
  297. },
  298. ],
  299.  
  300. TextMessage: [
  301. {
  302. id: uuid(),
  303. patientId: alexPatientId,
  304. practitionerId,
  305. body: 'from Chelsea 1',
  306. createdAt: new Date(2017, 0, 1, 12, 30, 0, 0),
  307. },
  308. {
  309. id: uuid(),
  310. patientId: alexPatientId,
  311. practitionerId,
  312. body: 'from Chelsea 2',
  313. createdAt: new Date(2017, 0, 6, 12, 30, 0, 0),
  314. },
  315. {
  316. id: uuid(),
  317. patientId: justinPatientId,
  318. practitionerId,
  319. body: 'from Chelsea2',
  320. createdAt: new Date(2017, 0, 2, 12, 30, 0, 0),
  321. },
  322. {
  323. id: uuid(),
  324. patientId: justinPatientId,
  325. practitionerId: practitionerId2,
  326. body: 'from Perry 1',
  327. createdAt: new Date(2017, 0, 3, 12, 30, 0, 0),
  328. },
  329. {
  330. id: uuid(),
  331. patientId: alexPatientId,
  332. practitionerId: practitionerId2,
  333. body: 'from Perry to alex 1',
  334. createdAt: new Date(2017, 0, 4, 11, 30, 0, 0),
  335. },
  336. {
  337. id: uuid(),
  338. patientId: alexPatientId,
  339. practitionerId: practitionerId2,
  340. body: 'from Perry to Alex 2',
  341. createdAt: new Date(2017, 0, 4, 12, 30, 0, 0),
  342. },
  343. ],
  344.  
  345. Chair: [
  346. {
  347. id: chairId,
  348. accountId: accountId,
  349. name: 'Chair 1',
  350. description: '',
  351. },
  352. ],
  353.  
  354. Token: [
  355. {
  356. id: uuid(),
  357. appointmentId: appointmentId1,
  358. },
  359. {
  360. id: uuid(),
  361. appointmentId: appointmentId2,
  362. },
  363. ],
  364. };
  365.  
  366.  
  367. console.log(SEEDS);
  368.  
  369. seedDatabase(SEEDS)
  370. .then(() => {
  371. console.log('Successfully executed bin/seeds.');
  372. process.exit();
  373. })
  374. .catch((err) => {
  375. console.error('Unsuccessfully executed bin/seeds.');
  376. console.error(err);
  377. process.exit(1);
  378. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement