Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
23 changes: 0 additions & 23 deletions .env.example

This file was deleted.

17 changes: 8 additions & 9 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Server Configuration (using different ports for testing)
PORT=4001
REST_PORT=4002
GRAPHQL_PORT=4003
# Test Database Configuration
DATABASE_URL=postgresql://postgres:test_password@localhost:5433/test_db?schema=public
DIRECT_URL=postgresql://postgres:test_password@localhost:5433/test_db?schema=public

# Application Configuration
# Environment
NODE_ENV=test
SEED_DATA=false

# Optional: Add any API keys or other configuration
# JWT_SECRET=your_jwt_secret_here
# CORS_ORIGIN=http://localhost:3000
# Server Configuration
PORT=3001
REST_PORT=3002
GRAPHQL_PORT=3003
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ logs/

# Coverage files
coverage/
REVIEW_SUMMARY.md
NONPROFIT_SORTING_IMPLEMENTATION.md
.gitignore
23 changes: 19 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions src/api/graphql/resolvers/nonprofits.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@ import {
createNonprofit,
createNonprofitSchema,
deleteNonprofit,
getAllNonprofits,
getNonprofitById,
getNonprofitsWithFilters,
updateNonprofit,
updateNonprofitSchema,
} from '../../../core';
import { GraphQLError } from 'graphql';
import { z } from 'zod';
import type {
StatusType,
NonprofitSortOption,
} from '../../../core/services/nonprofits.service';

// Infer TypeScript types directly from your Zod schemas
type CreateNonprofitInput = z.infer<typeof createNonprofitSchema>;
type UpdateNonprofitInput = z.infer<typeof updateNonprofitSchema>;

interface NonprofitsQueryArgs {
chapterIds?: string[];
statuses?: StatusType[];
sort?: NonprofitSortOption[];
}

export const nonprofitResolvers = {
Query: {
nonprofits: () => getAllNonprofits(),
nonprofits: (
_parent: unknown,
{ chapterIds, statuses, sort }: NonprofitsQueryArgs
) => {
return getNonprofitsWithFilters({ chapterIds, statuses, sort });
},
nonprofit: async (_parent: unknown, { id }: { id: string }) => {
const nonprofit = await getNonprofitById(id);
if (!nonprofit) {
Expand All @@ -43,10 +58,13 @@ export const nonprofitResolvers = {
},
updateNonprofit: (
_parent: unknown,
{ id, input }: { id: string; input: UpdateNonprofitInput }
{
nonprofit_id,
input,
}: { nonprofit_id: string; input: UpdateNonprofitInput }
) => {
const validatedInput = updateNonprofitSchema.parse(input);
return updateNonprofit(id, validatedInput);
return updateNonprofit(nonprofit_id, validatedInput);
},
deleteNonprofit: (_parent: unknown, { id }: { id: string }) => {
return deleteNonprofit(id);
Expand Down
14 changes: 13 additions & 1 deletion src/api/graphql/schemas/nonprofits.schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export const nonprofitSchemaString = `
enum NonprofitSortOption {
A_TO_Z
Z_TO_A
MOST_RECENT
STATUS
}

type Nonprofit {
nonprofit_id: ID!
name: String!
Expand All @@ -8,10 +15,15 @@ export const nonprofitSchemaString = `
contact_id: String!
created_at: String!
updated_at: String!
status: StatusType!
}

type Query {
nonprofits: [Nonprofit!]!
nonprofits(
chapterIds: [ID!]
statuses: [StatusType!]
sort: [NonprofitSortOption!]
): [Nonprofit!]!
nonprofit(id: ID!): Nonprofit
}

Expand Down
15 changes: 12 additions & 3 deletions src/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
import dotenv from 'dotenv';
import { z } from 'zod';

const envFilePath = (() => {
switch (process.env.NODE_ENV) {
case 'production':
return '.env';
case 'test':
return '.env.test';
default:
return '.env.local';
}
})();

dotenv.config({
// path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
// TODO: fix once we get our own test database set up that's not our prod database
path: '.env',
path: envFilePath,
});

// Define a schema for your environment variables
Expand Down
8 changes: 8 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export * from './services/roles.service';
export * from './services/sponsors.service';
export * from './services/volunteer.service';

// Export types for GraphQL resolvers
export type {
StatusType,
NonprofitSortOption,
GetNonprofitsFilters,
EnrichedNonprofit,
} from './services/nonprofits.service';

// Validators
export * from './validators/chapters.validator';
export * from './validators/companies.validator';
Expand Down
Loading
Loading