VendorSeeder.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import prisma from '../../src/prisma/PrismaClient';
  2. interface VendorInput {
  3. name: string;
  4. name_pt: string;
  5. strengths: string;
  6. weaknesses: string;
  7. website: string;
  8. }
  9. export async function seedVendors(): Promise<void> {
  10. try {
  11. // Cari user dengan username admin1
  12. const adminUser = await prisma.user.findFirst({
  13. where: {
  14. username: 'admin1',
  15. },
  16. });
  17. if (!adminUser) {
  18. throw new Error('User with username admin1 not found');
  19. }
  20. // Daftar vendor
  21. const vendors: VendorInput[] = [
  22. {
  23. name: 'MediSoft SIMRS',
  24. name_pt: 'PT Medisoft Technology',
  25. strengths: 'Antarmuka user-friendly, support lengkap untuk modul RS',
  26. weaknesses: 'Harga relatif tinggi',
  27. website: 'https://medisoft.co.id',
  28. },
  29. {
  30. name: 'SimRS Platinum',
  31. name_pt: 'PT Platinum Healthtech',
  32. strengths: 'Integrasi BPJS dan telemedicine',
  33. weaknesses: 'Customisasi sulit',
  34. website: 'https://simrsplatinum.id',
  35. },
  36. {
  37. name: 'Hospicare System',
  38. name_pt: 'PT Hospicare Nusantara',
  39. strengths: 'Stabil dan dokumentasi lengkap',
  40. weaknesses: 'Kurang inovatif',
  41. website: 'https://hospicare.co.id',
  42. },
  43. ];
  44. // Insert ke database
  45. for (const vendor of vendors) {
  46. await prisma.vendor.create({
  47. data: {
  48. ...vendor,
  49. created_by: adminUser.id,
  50. },
  51. });
  52. }
  53. console.log('✅ Vendor seeded!');
  54. } catch (error: any) {
  55. console.error('❌ Error seeding vendor:', error.message);
  56. }
  57. }
  58. // const prisma = require('../../src/prisma/PrismaClient.js');
  59. // async function seedVendors() {
  60. // try {
  61. // // cari user role admin
  62. // const adminUser = await prisma.user.findFirst({
  63. // where: {
  64. // username: 'admin1',
  65. // },
  66. // });
  67. // if (!adminUser) {
  68. // throw new Error('User with role admin not exists');
  69. // }
  70. // // Data vendor yang akan dimasukkan
  71. // const vendors = [
  72. // {
  73. // name: 'MediSoft SIMRS',
  74. // name_pt: 'PT Medisoft Technology',
  75. // strengths: 'Antarmuka user-friendly, support lengkap untuk modul RS',
  76. // weaknesses: 'Harga relatif tinggi',
  77. // website: 'https://medisoft.co.id',
  78. // },
  79. // {
  80. // name: 'SimRS Platinum',
  81. // name_pt: 'PT Platinum Healthtech',
  82. // strengths: 'Integrasi BPJS dan telemedicine',
  83. // weaknesses: 'Customisasi sulit',
  84. // website: 'https://simrsplatinum.id',
  85. // },
  86. // {
  87. // name: 'Hospicare System',
  88. // name_pt: 'PT Hospicare Nusantara',
  89. // strengths: 'Stabil dan dokumentasi lengkap',
  90. // weaknesses: 'Kurang inovatif',
  91. // website: 'https://hospicare.co.id',
  92. // },
  93. // ];
  94. // // Insert vendor dengan created_by dari adminUser.id
  95. // for (const vendor of vendors) {
  96. // await prisma.vendor.create({
  97. // data: {
  98. // ...vendor,
  99. // created_by: adminUser.id,
  100. // },
  101. // });
  102. // }
  103. // console.log('✅ Vendor seeded!');
  104. // } catch (error) {
  105. // console.error('❌ Error seeding vendor:', error);
  106. // }
  107. // }
  108. // module.exports = { seedVendors };