-
Notifications
You must be signed in to change notification settings - Fork 0
feat(DEV-144): completed #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Prabal-buzz
wants to merge
3
commits into
DEV-126
Choose a base branch
from
DEV-144
base: DEV-126
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { MiddlewareFn } from "type-graphql"; | ||
| import { MyContext } from "../types/MyContext"; | ||
| import { Utils } from "../utils"; | ||
|
|
||
| export const isAuth: MiddlewareFn<MyContext> = async ({ context }, next) => { | ||
| if (!context.token) { | ||
| throw new Error("Not authenticated - no token provided"); | ||
| } | ||
|
|
||
| try { | ||
| // Verify the JWT token and get the user | ||
| const user = await Utils.getUserFromJsWebToken(context.token); | ||
| // Store the user in context for use in resolvers | ||
| context.user = user; | ||
| return next(); | ||
| } catch (error) { | ||
| throw new Error("Not authenticated - invalid token"); | ||
| } | ||
| }; |
This file contains hidden or 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 hidden or 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,62 +1,87 @@ | ||
| import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, BaseEntity, ManyToOne, OneToMany, UpdateDateColumn, OneToOne, JoinColumn } from "typeorm"; | ||
| import { ObjectType, Field, ID } from "type-graphql"; | ||
| import { EventTicketBuys } from "./EventTicketBuys"; | ||
| import { Users } from "../../users"; | ||
| import { EventTicketCartReview } from "./EventTicketCartReview"; | ||
| import { Review } from "../../reviews/Review"; | ||
|
|
||
| @Entity() | ||
| @ObjectType() | ||
| export class EventTicketCart extends BaseEntity { | ||
| @Field(() => ID) | ||
| @PrimaryGeneratedColumn("uuid") | ||
| id: string; | ||
|
|
||
| @Field() | ||
| @Column({ default: 'guest' }) | ||
| type: "guest" | "user"; | ||
|
|
||
| @Field() | ||
| @Column({ default: "UNKNOWN" }) | ||
| name: string; | ||
|
|
||
| @Field() | ||
| @Column({ default: "UNKNOWN" }) | ||
| email: string; | ||
|
|
||
| @Field(() => Users, { nullable: true }) | ||
| @ManyToOne( () => Users, u => u.eventCarts, { onDelete: 'CASCADE', nullable: true }) | ||
| user?: Users | null; | ||
|
|
||
| @Field() | ||
| @Column() | ||
| completed: boolean; | ||
|
|
||
| @Field(() => Date, { nullable: true }) | ||
| @Column({ nullable: true }) | ||
| dateCompleted: Date; | ||
|
|
||
| @Field({ nullable: true }) | ||
| @Column({ nullable: true }) | ||
| checkIn: boolean; | ||
|
|
||
| @Field(() => Date, { nullable: true }) | ||
| @Column({ nullable: true }) | ||
| dateCheckIn: Date; | ||
|
|
||
| @Field() | ||
| @Column({ default: '' }) | ||
| qrCode: string; | ||
|
|
||
| @Field({ nullable: true }) | ||
| @Column({ nullable: true }) | ||
| stripeTransactionId: string; | ||
|
|
||
| @Field() | ||
| @Column() | ||
| eventId: string; | ||
|
|
||
| @Field(() => [EventTicketBuys]) | ||
| @OneToMany( () => EventTicketBuys, eTB => eTB.cart ) | ||
| tickets: EventTicketBuys[]; | ||
|
|
||
| @Field() | ||
| @CreateDateColumn() | ||
| created: Date; | ||
|
|
||
| @Field() | ||
| @UpdateDateColumn() | ||
| updated: Date; | ||
|
|
||
| @Field(() => Date, { nullable: true }) | ||
| @Column({ nullable: true }) | ||
| lastReviewEmailSent?: Date; | ||
|
|
||
| @Field() | ||
| @Column({ default: false }) | ||
| reviewCompleted: boolean; | ||
|
|
||
| @Field(() => EventTicketCartReview, { nullable: true }) | ||
| @OneToOne(() => EventTicketCartReview) | ||
| @JoinColumn() | ||
| review: EventTicketCartReview; | ||
|
|
||
| @Field(() => [Review]) | ||
| @OneToMany(() => Review, review => review.ticketCart) | ||
| reviews: Review[]; | ||
| } |
This file contains hidden or 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,25 +1,34 @@ | ||
| import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, BaseEntity } from "typeorm"; | ||
| import { ObjectType, Field, ID } from "type-graphql"; | ||
|
|
||
| @Entity() | ||
| @ObjectType() | ||
| export class EventTicketCartReview extends BaseEntity { | ||
| @Field(() => ID) | ||
| @PrimaryGeneratedColumn("uuid") | ||
| id: number | ||
| id: string | ||
|
|
||
| @Field() | ||
| @Column({ default: '' }) | ||
| name: string; | ||
|
|
||
| @Field() | ||
| @Column({ default: 0 }) | ||
| rating: number; | ||
|
|
||
| @Field({ nullable: true }) | ||
| @Column({ nullable: true }) | ||
| photo?: string; | ||
|
|
||
| @Field() | ||
| @Column({ default: '' }) | ||
| description: string; | ||
|
|
||
| @Field(() => Date, { nullable: true }) | ||
| @Column({ nullable: true }) | ||
| dateReviewCompleted: Date; | ||
|
|
||
| @Field() | ||
| @CreateDateColumn() | ||
| dateCreated: Date; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, BaseEntity, ManyToOne, OneToMany, JoinColumn } from "typeorm"; | ||
| import { ObjectType, Field, ID } from "type-graphql"; | ||
| import { ReviewQuestion } from "./ReviewQuestion"; | ||
| import { ReviewAnswer } from "./ReviewAnswer"; | ||
|
|
||
| @Entity() | ||
| @ObjectType() | ||
| export class DropDown extends BaseEntity { | ||
| @Field(() => ID) | ||
| @PrimaryGeneratedColumn("uuid") | ||
| id: string; | ||
|
|
||
| @Field() | ||
| @Column() | ||
| text: string; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this for proper type handling @Field()
@Column()
dataType: "string" | "number"; // This allows us to make sure when we are registering, rendering on client or server side it is being handled properly |
||
| @Field() | ||
| @Column() | ||
| value: string; | ||
|
|
||
| @Field() | ||
| @Column() | ||
| dataType: "string" | "number"; // This allows us to make sure when we are registering, rendering on | ||
|
|
||
| @CreateDateColumn() | ||
| @Field() | ||
| dateCreated: Date; | ||
|
|
||
| @UpdateDateColumn() | ||
| @Field() | ||
| dateModified: Date; | ||
|
|
||
| @Field(() => ReviewQuestion) | ||
| @ManyToOne(() => ReviewQuestion, reviewQuestion => reviewQuestion.dropDown, { onDelete: "CASCADE" }) | ||
| @JoinColumn() | ||
| reviewQuestion: ReviewQuestion; | ||
|
|
||
| @Field(() => [ReviewAnswer]) | ||
| @OneToMany(() => ReviewAnswer, reviewAnswer => reviewAnswer.dropDownAnswer, { cascade: true }) | ||
| reviewAnswers: ReviewAnswer[]; | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # Review System Models | ||
|
|
||
| This directory contains the models for the review system, which allows event organizers to create review campaigns with custom questions and collect feedback from attendees. | ||
|
|
||
| ## Models Overview | ||
|
|
||
| ### ReviewCampaign | ||
|
|
||
| The main entity that represents a review campaign for an event. | ||
|
|
||
| **Fields:** | ||
|
|
||
| - `id`: Unique identifier (UUID) | ||
| - `title`: Campaign title | ||
| - `description`: Campaign description | ||
| - `eventId`: Reference to the event this campaign belongs to | ||
| - `questions`: Array of review questions | ||
| - `for`: Whether this campaign is for "all" attendees or specific "ticket_type" | ||
| - `for_id`: If for ticket_type, contains ticket type identifier(s) | ||
| - `dateCreated`: Creation timestamp | ||
| - `dateModified`: Last modification timestamp | ||
| - `reviews`: Array of reviews submitted for this campaign | ||
|
|
||
| ### ReviewQuestion | ||
|
|
||
| Represents a question within a review campaign. | ||
|
|
||
| **Fields:** | ||
|
|
||
| - `id`: Unique identifier (UUID) | ||
| - `question`: The question text | ||
| - `questionType`: Type of question ("text", "range", "dropdown") | ||
| - `rangeMin`: Minimum value for range questions (nullable) | ||
| - `rangeMax`: Maximum value for range questions (nullable) | ||
| - `dropDown`: Array of dropdown options (for dropdown questions) | ||
| - `createdAt`: Creation timestamp | ||
| - `modifiedAt`: Last modification timestamp | ||
| - `reviewCampaign`: Reference to the parent campaign | ||
|
|
||
| ### DropDown | ||
|
|
||
| Represents a dropdown option for dropdown-type questions. | ||
|
|
||
| **Fields:** | ||
|
|
||
| - `id`: Unique identifier (UUID) | ||
| - `text`: Display text for the option | ||
| - `value`: Value associated with the option | ||
| - `dateCreated`: Creation timestamp | ||
| - `dateModified`: Last modification timestamp | ||
| - `reviewQuestion`: Reference to the parent question | ||
|
|
||
| ### Review | ||
|
|
||
| Represents a completed review submission. | ||
|
|
||
| **Fields:** | ||
|
|
||
| - `id`: Unique identifier (UUID) | ||
| - `reviewCampaign`: Reference to the campaign this review belongs to | ||
| - `answers`: Array of answers to the campaign questions | ||
| - `dateReviewCompleted`: When the review was completed | ||
| - `dateCreated`: Creation timestamp | ||
|
|
||
| ### ReviewAnswer | ||
|
|
||
| Represents an answer to a specific question within a review. | ||
|
|
||
| **Fields:** | ||
|
|
||
| - `id`: Unique identifier (UUID) | ||
| - `review`: Reference to the parent review | ||
| - `questionId`: Reference to the question being answered | ||
| - `questionType`: Type of the question (for validation) | ||
| - `textAnswer`: Text answer (for text questions) | ||
| - `rangeAnswer`: Numeric answer (for range questions) | ||
| - `dropDownAnswer`: Selected dropdown option (for dropdown questions) | ||
| - `createdAt`: Creation timestamp | ||
| - `modifiedAt`: Last modification timestamp | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| ### Creating a Review Campaign | ||
|
|
||
| ```typescript | ||
| const campaign = await ReviewCampaign.create({ | ||
| title: "Event Feedback 2024", | ||
| description: "Please provide feedback about our event", | ||
| eventId: event, | ||
| for: "all", | ||
| questions: [ | ||
| { | ||
| question: "How would you rate the event?", | ||
| questionType: "range", | ||
| rangeMin: 1, | ||
| rangeMax: 5, | ||
| }, | ||
| { | ||
| question: "What was your favorite part?", | ||
| questionType: "text", | ||
| }, | ||
| { | ||
| question: "Would you attend again?", | ||
| questionType: "dropdown", | ||
| dropDown: [ | ||
| { text: "Yes", value: "yes" }, | ||
| { text: "No", value: "no" }, | ||
| { text: "Maybe", value: "maybe" }, | ||
| ], | ||
| }, | ||
| ], | ||
| }).save(); | ||
| ``` | ||
|
|
||
| ### Submitting a Review | ||
|
|
||
| ```typescript | ||
| const review = await Review.create({ | ||
| reviewCampaign: campaign, | ||
| dateReviewCompleted: new Date(), | ||
| }).save(); | ||
|
|
||
| const answers = [ | ||
| { | ||
| review: review, | ||
| questionId: question1, | ||
| questionType: "range", | ||
| rangeAnswer: 5, | ||
| }, | ||
| { | ||
| review: review, | ||
| questionId: question2, | ||
| questionType: "text", | ||
| textAnswer: "The food was amazing!", | ||
| }, | ||
| { | ||
| review: review, | ||
| questionId: question3, | ||
| questionType: "dropdown", | ||
| dropDownAnswer: dropdownOption, | ||
| }, | ||
| ]; | ||
|
|
||
| await ReviewAnswer.save(answers); | ||
| ``` | ||
|
|
||
| ## GraphQL Queries and Mutations | ||
|
|
||
| The system provides comprehensive GraphQL operations: | ||
|
|
||
| ### Queries | ||
|
|
||
| - `getReviewCampaigns(eventId)`: Get all campaigns for an event | ||
| - `getReviewCampaign(id)`: Get a specific campaign with questions and reviews | ||
| - `getReviewCampaignsForUser(eventId, ticketType)`: Get campaigns available to a user | ||
| - `getReviewsForCampaign(campaignId)`: Get all reviews for a campaign | ||
| - `getReview(id)`: Get a specific review with answers | ||
|
|
||
| ### Mutations | ||
|
|
||
| - `createReviewCampaign(input)`: Create a new review campaign | ||
| - `updateReviewCampaign(input)`: Update an existing campaign | ||
| - `deleteReviewCampaign(id)`: Delete a campaign | ||
| - `addQuestionToCampaign(input)`: Add a question to an existing campaign | ||
| - `updateQuestion(input)`: Update a question | ||
| - `deleteQuestion(id)`: Delete a question | ||
| - `submitReview(input)`: Submit a new review | ||
| - `updateReview(input)`: Update an existing review | ||
|
|
||
| ## Database Migration | ||
|
|
||
| Run the migration to create the necessary database tables: | ||
|
|
||
| ```bash | ||
| npm run typeorm migration:run | ||
| ``` | ||
|
|
||
| The migration file `1700000000000-CreateReviewTables.ts` will create all the required tables with proper foreign key relationships. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what your trying to do with this isAuth, but this implementation won't work, for two reason, in session_token is only savedd user side not on backend side. Second reason the session_token that is saved on client side, is a hashed token so we won't be able to have session.userId.
and also a user can have a session.userId, but we still need to verify what ever token is given. Please do not use this middleware as it doesn't work. Or modify it, in a way that does work. To figure what to see if it works or not, check other examples of how we logged user in, and verified their token.