-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Cloudinary uploads for Event Assets (#67)
- Loading branch information
Showing
17 changed files
with
486 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export const events = { | ||
NewEventAdded: "NewEventAdded", //replace with event identify | ||
RegisteredForEvent: "RegisteredForEvent", | ||
EventAttendanceMark: "EventAttendanceMark", | ||
EndEventRegistration: "EndEventRegistration", | ||
RSVPForEvent: "RSVPForEvent" | ||
NewEventAdded: "0x1", //replace with event identify | ||
RegisteredForEvent: "0x2", | ||
EventAttendanceMark: "0x3", | ||
EndEventRegistration: "0x4", | ||
RSVPForEvent: "0x5" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,156 @@ | ||
import { | ||
NewEventAdded, | ||
RegisteredForEvent, | ||
EventAttendanceMark, | ||
EndEventRegistration, | ||
RSVPForEvent | ||
import { | ||
NewEventAdded, | ||
RegisteredForEvent, | ||
EventAttendanceMark, | ||
EndEventRegistration, | ||
RSVPForEvent, | ||
} from "./types"; | ||
import { FieldElement, v1alpha2 as starknet } from '@apibara/starknet'; | ||
import { FieldElement, v1alpha2 as starknet } from "@apibara/starknet"; | ||
import Event from "../models/Event.js"; | ||
import { uint256 } from 'starknet'; | ||
import { uint256 } from "starknet"; | ||
import { hexToAscii } from "../utils/tohexAscii.js"; | ||
|
||
export async function handleNewEventAdded(event: starknet.IEvent) { | ||
const data = event.data!; | ||
const data = event.data!; | ||
|
||
const eventDetails: NewEventAdded = { | ||
name: hexToAscii(FieldElement.toHex(data[0]).toString()), | ||
event_id: parseInt(uint256 | ||
const eventDetails: NewEventAdded = { | ||
name: hexToAscii(FieldElement.toHex(data[0]).toString()), | ||
event_id: parseInt( | ||
uint256 | ||
.uint256ToBN({ | ||
low: FieldElement.toBigInt(data[1]), | ||
high: FieldElement.toBigInt(data[2]), | ||
}) | ||
.toString()), | ||
location: hexToAscii(FieldElement.toHex(data[3]).toString()), | ||
event_owner: FieldElement.toHex(data[4]).toString() | ||
}; | ||
|
||
//Debugging purposes | ||
console.log(eventDetails); | ||
|
||
const eventExists = await Event.findByEventId(eventDetails.event_id); | ||
if (eventExists) { | ||
console.log("Event already exists"); | ||
return; | ||
} | ||
await Event.create(eventDetails); | ||
.toString() | ||
), | ||
location: hexToAscii(FieldElement.toHex(data[3]).toString()), | ||
event_owner: FieldElement.toHex(data[4]).toString(), | ||
}; | ||
|
||
//Debugging purposes | ||
console.log(eventDetails); | ||
|
||
const eventExists = await Event.findByEventId(eventDetails.event_id); | ||
if (eventExists) { | ||
console.log("Event already exists"); | ||
return; | ||
} | ||
await Event.create(eventDetails); | ||
} | ||
|
||
export async function handleRegisteredForEvent(event: starknet.IEvent) { | ||
const data = event.data!; | ||
const data = event.data!; | ||
|
||
const registeredForEvent: RegisteredForEvent = { | ||
event_id: parseInt(uint256 | ||
const registeredForEvent: RegisteredForEvent = { | ||
event_id: parseInt( | ||
uint256 | ||
.uint256ToBN({ | ||
low: FieldElement.toBigInt(data[0]), | ||
high: FieldElement.toBigInt(data[1]), | ||
}) | ||
.toString()), | ||
event_name: hexToAscii(FieldElement.toHex(data[2]).toString()), | ||
user_address: FieldElement.toHex(data[3]).toString() | ||
}; | ||
|
||
console.log(registeredForEvent); | ||
|
||
const hasRegistered = await Event.isUserRegistered(registeredForEvent.event_id, registeredForEvent.user_address); | ||
if (hasRegistered) { | ||
console.log("User has already registered"); | ||
return; | ||
} | ||
await Event.registerUser(registeredForEvent.event_id, registeredForEvent.user_address); | ||
.toString() | ||
), | ||
event_name: hexToAscii(FieldElement.toHex(data[2]).toString()), | ||
user_address: FieldElement.toHex(data[3]).toString(), | ||
}; | ||
|
||
console.log(registeredForEvent); | ||
|
||
const hasRegistered = await Event.isUserRegistered( | ||
registeredForEvent.event_id, | ||
registeredForEvent.user_address | ||
); | ||
if (hasRegistered) { | ||
console.log("User has already registered"); | ||
return; | ||
} | ||
await Event.registerUser( | ||
registeredForEvent.event_id, | ||
registeredForEvent.user_address | ||
); | ||
} | ||
|
||
export async function handleEventAttendanceMark(event: starknet.IEvent) { | ||
const data = event.data!; | ||
const data = event.data!; | ||
|
||
const eventAttendanceMark: EventAttendanceMark = { | ||
event_id: parseInt(uint256 | ||
const eventAttendanceMark: EventAttendanceMark = { | ||
event_id: parseInt( | ||
uint256 | ||
.uint256ToBN({ | ||
low: FieldElement.toBigInt(data[0]), | ||
high: FieldElement.toBigInt(data[1]), | ||
}) | ||
.toString()), | ||
user_address: FieldElement.toHex(data[2]).toString() | ||
}; | ||
|
||
console.log(eventAttendanceMark); | ||
|
||
const hasMarkedAttendance = await Event.hasUserAttended(eventAttendanceMark.event_id, eventAttendanceMark.user_address); | ||
if (hasMarkedAttendance) { | ||
console.log("User has already marked attendance"); | ||
return; | ||
} | ||
await Event.markAttendance(eventAttendanceMark.event_id, eventAttendanceMark.user_address); | ||
.toString() | ||
), | ||
user_address: FieldElement.toHex(data[2]).toString(), | ||
}; | ||
|
||
console.log(eventAttendanceMark); | ||
|
||
const hasMarkedAttendance = await Event.hasUserAttended( | ||
eventAttendanceMark.event_id, | ||
eventAttendanceMark.user_address | ||
); | ||
if (hasMarkedAttendance) { | ||
console.log("User has already marked attendance"); | ||
return; | ||
} | ||
await Event.markAttendance( | ||
eventAttendanceMark.event_id, | ||
eventAttendanceMark.user_address | ||
); | ||
} | ||
|
||
export async function handleEndEventRegistration(event: starknet.IEvent) { | ||
const data = event.data!; | ||
const data = event.data!; | ||
|
||
const endEventRegistration: EndEventRegistration = { | ||
event_id: parseInt(uint256 | ||
const endEventRegistration: EndEventRegistration = { | ||
event_id: parseInt( | ||
uint256 | ||
.uint256ToBN({ | ||
low: FieldElement.toBigInt(data[0]), | ||
high: FieldElement.toBigInt(data[1]), | ||
}) | ||
.toString()), | ||
event_name: hexToAscii(FieldElement.toHex(data[2]).toString()), | ||
event_owner: FieldElement.toHex(data[3]).toString() | ||
}; | ||
|
||
console.log(endEventRegistration); | ||
|
||
const eventExists = await Event.findByEventId(endEventRegistration.event_id); | ||
if (!eventExists) { | ||
console.log("Event does not exist"); | ||
return; | ||
} | ||
await Event.endRegistration(endEventRegistration.event_id); | ||
.toString() | ||
), | ||
event_name: hexToAscii(FieldElement.toHex(data[2]).toString()), | ||
event_owner: FieldElement.toHex(data[3]).toString(), | ||
}; | ||
|
||
console.log(endEventRegistration); | ||
|
||
const eventExists = await Event.findByEventId(endEventRegistration.event_id); | ||
if (!eventExists) { | ||
console.log("Event does not exist"); | ||
return; | ||
} | ||
await Event.endRegistration(endEventRegistration.event_id); | ||
} | ||
|
||
export async function handleRSVPForEvent(event: starknet.IEvent) { | ||
const data = event.data!; | ||
const data = event.data!; | ||
|
||
const rsvpForEvent: RSVPForEvent = { | ||
event_id: parseInt(uint256 | ||
const rsvpForEvent: RSVPForEvent = { | ||
event_id: parseInt( | ||
uint256 | ||
.uint256ToBN({ | ||
low: FieldElement.toBigInt(data[0]), | ||
high: FieldElement.toBigInt(data[1]), | ||
}) | ||
.toString()), | ||
attendee_address: FieldElement.toHex(data[2]).toString() | ||
}; | ||
|
||
console.log(rsvpForEvent); | ||
|
||
const hasRSVPed = await Event.hasUserRSVPed(rsvpForEvent.event_id, rsvpForEvent.attendee_address); | ||
if (hasRSVPed) { | ||
console.log("User has already RSVPed"); | ||
return; | ||
} | ||
await Event.addRSVP(rsvpForEvent.event_id, rsvpForEvent.attendee_address); | ||
} | ||
.toString() | ||
), | ||
attendee_address: FieldElement.toHex(data[2]).toString(), | ||
}; | ||
|
||
console.log(rsvpForEvent); | ||
|
||
const hasRSVPed = await Event.hasUserRSVPed( | ||
rsvpForEvent.event_id, | ||
rsvpForEvent.attendee_address | ||
); | ||
if (hasRSVPed) { | ||
console.log("User has already RSVPed"); | ||
return; | ||
} | ||
await Event.addRSVP(rsvpForEvent.event_id, rsvpForEvent.attendee_address); | ||
} |
Oops, something went wrong.