VendorSeeder.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.userKeycloak.findFirst({
  13. where: {
  14. id: 'd3dcbbbd-fc92-45cf-9520-d0a6859358f6',
  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. seedVendors();
  59. // const prisma = require('../../src/prisma/PrismaClient.js');
  60. // async function seedVendors() {
  61. // try {
  62. // // cari user role admin
  63. // const adminUser = await prisma.user.findFirst({
  64. // where: {
  65. // username: 'admin1',
  66. // },
  67. // });
  68. // if (!adminUser) {
  69. // throw new Error('User with role admin not exists');
  70. // }
  71. // // Data vendor yang akan dimasukkan
  72. // const vendors = [
  73. // {
  74. // name: 'MediSoft SIMRS',
  75. // name_pt: 'PT Medisoft Technology',
  76. // strengths: 'Antarmuka user-friendly, support lengkap untuk modul RS',
  77. // weaknesses: 'Harga relatif tinggi',
  78. // website: 'https://medisoft.co.id',
  79. // },
  80. // {
  81. // name: 'SimRS Platinum',
  82. // name_pt: 'PT Platinum Healthtech',
  83. // strengths: 'Integrasi BPJS dan telemedicine',
  84. // weaknesses: 'Customisasi sulit',
  85. // website: 'https://simrsplatinum.id',
  86. // },
  87. // {
  88. // name: 'Hospicare System',
  89. // name_pt: 'PT Hospicare Nusantara',
  90. // strengths: 'Stabil dan dokumentasi lengkap',
  91. // weaknesses: 'Kurang inovatif',
  92. // website: 'https://hospicare.co.id',
  93. // },
  94. // ];
  95. // // Insert vendor dengan created_by dari adminUser.id
  96. // for (const vendor of vendors) {
  97. // await prisma.vendor.create({
  98. // data: {
  99. // ...vendor,
  100. // created_by: adminUser.id,
  101. // },
  102. // });
  103. // }
  104. // console.log('✅ Vendor seeded!');
  105. // } catch (error) {
  106. // console.error('❌ Error seeding vendor:', error);
  107. // }
  108. // }
  109. // module.exports = { seedVendors };