Skip to content

Commit

Permalink
feat: upsert attendees
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyuujin committed Jul 6, 2024
1 parent 0f3e756 commit 98e7c96
Show file tree
Hide file tree
Showing 4 changed files with 721 additions and 3 deletions.
13 changes: 12 additions & 1 deletion apps/peatix-adapter/src/peatix-order/peatix-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ScraperPage } from '../scraper-page/scraper-page'
import { HttpService } from '@nestjs/axios'
import { JSON_USAGE, PUPPETEER_USAGE } from '../features'
import { SupabaseService } from 'src/supabase/supabase.service'
import { AttendeeReceipt } from 'src/types/supabase'

const { parse } = require('csv-parse/sync')

Expand Down Expand Up @@ -168,8 +169,18 @@ export class PeatixOrderService extends ScraperPage {
const attendees = res
this.logger.log(attendees)

const receipts: AttendeeReceipt[] = attendees.map((attendee) => {
const receiptId = attendee[Object.keys(attendee)[0]]
const ticketName = attendee[Object.keys(attendee)[4]]

// チケット名から参加者の種別を特定する

return { role: 'attendee', receipt_id: receiptId }
})
this.logger.log(receipts)

// Peatix 購入情報を Supabase へ反映する
await this.supabaseService.updateAttendees()
// await this.supabaseService.updateAttendees(receipts)
})
}

Expand Down
13 changes: 11 additions & 2 deletions apps/peatix-adapter/src/supabase/supabase.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, Logger } from '@nestjs/common'
import { SupabaseClient, createClient } from '@supabase/supabase-js'
import { EnvService } from 'src/env/env.service'
import { AttendeeReceipt } from 'src/types/supabase'

@Injectable()
export class SupabaseService {
Expand Down Expand Up @@ -32,7 +33,15 @@ export class SupabaseService {
}

// vuejs-jp/vuefes-2024-backside#226
public async updateAttendees() {
//
public async updateAttendees(targets: AttendeeReceipt[]) {
const targetData = [ ...targets ]

for (const target of targetData) {
const { data, error } = await this.client.from('attendees')
.upsert({ role: target.role, activated_at: new Date().toISOString() })
.eq('receipt_id', target.receipt_id)
.eq('activated_at', null)
if (error) break
}
}
}
Loading

0 comments on commit 98e7c96

Please sign in to comment.