Skip to content

Commit

Permalink
feat: remove auth to test iam connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Smith committed Feb 26, 2024
1 parent 100591f commit 2de09b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
15 changes: 10 additions & 5 deletions src/handlers/privateResolver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { AppSyncResolverHandler } from 'aws-lambda';
import { MutationInsertSignUpDataArgs } from '../../appsync';
import { MutationInsertSignUpDataArgs, SignUpData } from '../../appsync';
import { logger } from '../shared/logger';
import { SignUpDataRepository } from '../repository/signUpDataRepository';
import { MongoClient } from 'mongodb';

const signUpDataRepository = SignUpDataRepository.getInstance();
const client = new MongoClient(
process?.env?.MONGODB_CONNECTION_STRING ?? 'mongodb://localhost:27017/'
);

const db = client.db('D2E');
const collection = db.collection<SignUpData>('SignUps');

export const handler: AppSyncResolverHandler<MutationInsertSignUpDataArgs, boolean> = async (
event,
Expand All @@ -17,9 +22,9 @@ export const handler: AppSyncResolverHandler<MutationInsertSignUpDataArgs, boole
logger.info(`${JSON.stringify(params)}`);

switch (info.fieldName) {
case 'insertSignUpDataPrivate': {
case 'testPrivate': {
const { id, email, type } = params;
const res = await signUpDataRepository.insert({ id, email, type });
const res = (await collection.insertOne({ id, email, type })).acknowledged;
callback(null, res);
break;
}
Expand Down
32 changes: 11 additions & 21 deletions src/handlers/publicResolver.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { AppSyncResolverHandler } from 'aws-lambda';
import { School, QueryGetSchoolByNameArgs } from '../../appsync';
import { QueryGetSchoolByNameArgs, SignUpData } from '../../appsync';
import { logger } from '../shared/logger';
import { SchoolDataRepository } from '../repository/schoolDataRepository';
import { MongoClient } from 'mongodb';

const schoolDataRepository = SchoolDataRepository.getInstance();
const client = new MongoClient(
process?.env?.MONGODB_CONNECTION_STRING ?? 'mongodb://localhost:27017/'
);

export const handler: AppSyncResolverHandler<QueryGetSchoolByNameArgs, School> = async (
const db = client.db('D2E');
const collection = db.collection<SignUpData>('SignUps');
export const handler: AppSyncResolverHandler<QueryGetSchoolByNameArgs, SignUpData[]> = async (
event,
context,
callback
Expand All @@ -17,14 +21,9 @@ export const handler: AppSyncResolverHandler<QueryGetSchoolByNameArgs, School> =
logger.info(`${JSON.stringify(params)}`);

switch (info.fieldName) {
case 'getSchoolByNamePublic': {
const { name } = params;
const school = await schoolDataRepository.getByName(name);
if (!school) {
callback(null);
break;
}
callback(null, removeFields<School>(info.selectionSetList, school));
case 'testPublic': {
const res = await collection.find({}).toArray();
callback(null, res);
break;
}
default: {
Expand All @@ -35,12 +34,3 @@ export const handler: AppSyncResolverHandler<QueryGetSchoolByNameArgs, School> =

throw new Error('An unknown error occurred');
};

const removeFields = <T extends object>(selectionSetList: string[], obj: T): T => {
return Object.entries(obj).reduce((acc, [key, value]) => {
if (selectionSetList.includes(key)) {
acc = { ...acc, [key]: value as string };
}
return acc;
}, {} as T);
};

0 comments on commit 2de09b0

Please sign in to comment.