Skip to content
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

implemented draft of getAllCampaigns() #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/resolvers/campaign.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,33 @@ import { Resolver, Query, Args } from '@nestjs/graphql';
import { PrismaService } from 'src/prisma/prisma.service';
import { Campaign } from './models/campaign.model';
import { NotFoundException, BadRequestException } from '@nestjs/common';
import { Logger } from '@nestjs/common';

@Resolver(() => Campaign)
export class CampaignResolver {
private readonly logger = new Logger(CampaignResolver.name);

constructor(private prismaService: PrismaService) {}

@Query(() => [Campaign], {
name: 'getAllCampaigns',
nullable: 'items'
})
async getAllCampaigns(): Promise<Campaign[]> {
try {
const campaigns = await this.prismaService.campaign.findMany({
orderBy: {
createdAt: 'desc'
}
});
return campaigns;
} catch (error) {
this.logger.error('Failed to retrieve campaigns', error.stack);
throw new Error('Unable to retrieve campaigns. Please try again later.');
}
}
}

@Query(() => Campaign, { nullable: true })
async getCampaignById(@Args('id') id: number): Promise<Campaign | null> {
// Validate ID format (assuming UUID format)
Expand All @@ -27,4 +49,4 @@ export class CampaignResolver {

return campaign;
}
}
}
7 changes: 4 additions & 3 deletions src/resolvers/resolvers.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Module } from '@nestjs/common';
import { CampaignResolver } from './campaign.resolver';
import { PrismaModule } from 'src/prisma/prisma.module';

@Module({
providers: [CampaignResolver],
exports: [CampaignResolver],
imports: [PrismaModule],
providers: [CampaignResolver]

Check failure on line 7 in src/resolvers/resolvers.module.ts

View workflow job for this annotation

GitHub Actions / lint-and-build-backend

Insert `,`
})
export class ResolversModule {}
export class ResolversModule {}

Check failure on line 9 in src/resolvers/resolvers.module.ts

View workflow job for this annotation

GitHub Actions / lint-and-build-backend

Insert `⏎`
Loading