Advertisement
Guest User

Untitled

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