-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update diagram * chore: move test route logic to separate file * feat: add manual testing endpoints * fix: adding cron detail type in staging * chore: use getFunctionProps in SchedulerStack * feat: add manual testing for squadjoin * fix: adding schedule detail in staging * chore: separate function permissions and roles into multiple groups * fix: binding db to functions * chore: create lambda result utils * fix: send back empty json if no body is provided
- Loading branch information
Showing
22 changed files
with
413 additions
and
180 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { and, eq } from "drizzle-orm"; | ||
|
||
import { db } from "@/db/index"; | ||
import { users } from "@/db/schema"; | ||
|
||
export const deleteUser = async (userId: string, teamId: string) => { | ||
await db | ||
.delete(users) | ||
.where(and(eq(users.id, userId), eq(users.teamId, teamId))); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { eq } from "drizzle-orm"; | ||
|
||
import { db } from "@/db/index"; | ||
import { users } from "@/db/schema"; | ||
|
||
export const getUser = async (userId: string) => | ||
db.query.users.findFirst({ | ||
where: eq(users.id, userId), | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; | ||
import { Config } from "sst/node/config"; | ||
|
||
import { publishEvent } from "@/utils/eventBridge/publishEvent"; | ||
import { errorResult, okResult } from "@/utils/lambda/result"; | ||
|
||
export const handler: APIGatewayProxyHandlerV2 = async () => { | ||
try { | ||
await publishEvent("botJoined", { | ||
channel: Config.CORE_SLACK_CHANNEL_ID, | ||
}); | ||
|
||
return okResult("Event sent"); | ||
} catch (error) { | ||
console.error(`Error sending manual botJoined event: ${error}`); | ||
|
||
return errorResult(error); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; | ||
|
||
import { getUser } from "@/db/queries/getUser"; | ||
import { publishEvent } from "@/utils/eventBridge/publishEvent"; | ||
import { errorResult, okResult } from "@/utils/lambda/result"; | ||
|
||
export const handler: APIGatewayProxyHandlerV2 = async (request) => { | ||
try { | ||
if (!request.queryStringParameters?.userId) { | ||
throw new Error("No userId"); | ||
} | ||
|
||
const user = await getUser(request.queryStringParameters.userId); | ||
|
||
if (!user) { | ||
throw new Error("User not found"); | ||
} | ||
|
||
await publishEvent("askPresentAndSquadJoinFromTeam", { | ||
birthdayPerson: user.id, | ||
team: user.teamId, | ||
}); | ||
|
||
return okResult("Event sent"); | ||
} catch (error) { | ||
console.error(`Error sending manual botJoined event: ${error}`); | ||
|
||
return errorResult(error); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; | ||
import { Config } from "sst/node/config"; | ||
|
||
import { publishEvent } from "@/utils/eventBridge/publishEvent"; | ||
import { errorResult, okResult } from "@/utils/lambda/result"; | ||
|
||
export const handler: APIGatewayProxyHandlerV2 = async (request) => { | ||
try { | ||
if (!request.queryStringParameters?.userId) { | ||
throw new Error("No userId"); | ||
} | ||
|
||
await publishEvent("memberJoinedChannel", { | ||
channel: Config.CORE_SLACK_CHANNEL_ID, | ||
user: request.queryStringParameters.userId, | ||
}); | ||
|
||
return okResult("Event sent"); | ||
} catch (error) { | ||
console.error(`Error sending manual userJoined event: ${error}`); | ||
|
||
return errorResult(error); | ||
} | ||
}; |
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
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const okResult = (body?: unknown) => ({ | ||
statusCode: 200, | ||
body: JSON.stringify(body ?? {}, null, 2), | ||
}); | ||
|
||
export const errorResult = (error: unknown) => ({ | ||
statusCode: 500, | ||
body: JSON.stringify( | ||
{ | ||
error, | ||
}, | ||
null, | ||
2, | ||
), | ||
}); |
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
Oops, something went wrong.