Skip to content

Commit

Permalink
feat(activityHost): create activity host before create activity
Browse files Browse the repository at this point in the history
  • Loading branch information
voyager-seb committed Dec 20, 2024
1 parent 62f5810 commit b8c2930
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
8 changes: 0 additions & 8 deletions src/app/api/activityHosts/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function StepperActivitiesCreate() {
mutate(review, {
onSuccess: () => {
setCreatingActivity(false)
// setOpenSuccessDialog(true)
setOpenSuccessDialog(true)
},
onError: () => {
setCreatingActivity(false)
Expand Down
42 changes: 20 additions & 22 deletions src/services/domain/activities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,30 @@ export async function postActivity(newActivity: ActivityType) {
const supabaseClient = createAnonymousClient()
const bannerSrc = newActivity.banner_src
delete newActivity.banner_src
const httpInstance = axios.create({
baseURL: '/api',
})
const activityHost: ActivityHost = {
id: newActivity.activity_host_id,
name: 'Nombresito',
address: 'Addresita'
wallet_address: 'Addresita'
}
const activityHostResponse = httpInstance.post<ActivityType>('/activityHosts', activityHost)
console.log(activityHostResponse)
// const { data, error } = await supabaseClient.from(ACTIVITIES).insert([newActivity]).select()
// if (error) return NextResponse.json(error)
// console.log('Activity created successfully')

// const activityId = data[0].id
// const mimeType = bannerSrc?.split(';')[0].split(':')[1]
// const extension = mimeType === 'image/png' ? 'png' : 'jpg'
// const bannerPath = `${bannerBasePath}/${activityId}.${extension}`
// data[0].banner_path = bannerPath
// console.log('Uploading activity banner')
// await uploadFile(supabaseBucket, bannerPath, bannerSrc as string)
// console.log('Setting activity banner path')
// updateActivity(data[0])
// data[0].banner_src = bannerSrc
// return NextResponse.json(data[0])
return NextResponse.json({message: 'OK'})
console.log('Creating activity host')
const {data: activityHostData, error: activityHostError} = await supabaseClient.from('activity_hosts').insert([activityHost]).select()
console.log('Error: ', activityHostData)
console.log('ActivityHostData: ', activityHostError)
const { data, error } = await supabaseClient.from(ACTIVITIES).insert([newActivity]).select()
if (error) return NextResponse.json(error)
console.log('Activity created successfully')

const activityId = data[0].id
const mimeType = bannerSrc?.split(';')[0].split(':')[1]
const extension = mimeType === 'image/png' ? 'png' : 'jpg'
const bannerPath = `${bannerBasePath}/${activityId}.${extension}`
data[0].banner_path = bannerPath
console.log('Uploading activity banner')
await uploadFile(supabaseBucket, bannerPath, bannerSrc as string)
console.log('Setting activity banner path')
updateActivity(data[0])
data[0].banner_src = bannerSrc
return NextResponse.json(data[0])
}

export async function putActivity(updatedActivity: ActivityType) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/activityHosts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ActivityHost = {
id: string
name: string
address: string
wallet_address: string
}

0 comments on commit b8c2930

Please sign in to comment.