PapuaTengahCitySeeder.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import prisma from '../../../src/prisma/PrismaClient';
  2. import { now } from '../../../src/utils/TimeLocal';
  3. const cityNames: string[] = [
  4. 'Kabupaten Deiyai',
  5. 'Kabupaten Dogiyai',
  6. 'Kabupaten Intan Jaya',
  7. 'Kabupaten Mimika',
  8. 'Kabupaten Nabire',
  9. 'Kabupaten Paniai',
  10. 'Kabupaten Puncak',
  11. 'Kabupaten Puncak Jaya',
  12. ];
  13. export const seedPapuaTengahCities = async (): Promise<void> => {
  14. const province = await prisma.province.findFirst({
  15. where: { name: 'Papua Tengah' },
  16. });
  17. if (!province) {
  18. console.error('❌ Province Papua Tengah not found. Seed it first.');
  19. return;
  20. }
  21. for (const name of cityNames) {
  22. await prisma.city.upsert({
  23. where: {
  24. name_province_id: {
  25. name,
  26. province_id: province.id,
  27. },
  28. },
  29. update: {
  30. updatedAt: now().toDate(),
  31. },
  32. create: {
  33. name,
  34. province_id: province.id,
  35. createdAt: now().toDate(),
  36. },
  37. });
  38. }
  39. console.log('✅ Papua Tengah City seeded!.');
  40. };
  41. // const prisma = require('../../../src/prisma/PrismaClient.js');
  42. // const timeLocal = require('../../../src/utils/TimeLocal.js')
  43. // const cityNames = [
  44. // 'Kabupaten Deiyai',
  45. // 'Kabupaten Dogiyai',
  46. // 'Kabupaten Intan Jaya',
  47. // 'Kabupaten Mimika',
  48. // 'Kabupaten Nabire',
  49. // 'Kabupaten Paniai',
  50. // 'Kabupaten Puncak',
  51. // 'Kabupaten Puncak Jaya'
  52. // // 8
  53. // ];
  54. // exports.seedPapuaTengahCities = async () => {
  55. // const province = await prisma.province.findFirst({
  56. // where: { name: 'Papua Tengah' },
  57. // });
  58. // if (!province) {
  59. // console.error('❌ Province Papua Tengah not found. Seed it first.');
  60. // return;
  61. // }
  62. // for (const name of cityNames) {
  63. // await prisma.city.upsert({
  64. // where: {
  65. // name_province_id: {
  66. // name,
  67. // province_id: province.id,
  68. // },
  69. // },
  70. // update: { updatedAt: timeLocal.now().toDate() },
  71. // create: {
  72. // name,
  73. // province_id: province.id,
  74. // createdAt: timeLocal.now().toDate()
  75. // },
  76. // });
  77. // }
  78. // console.log('✅ Papua Tengah City seeded!.');
  79. // };