Skip to content

Commit

Permalink
Formatted verify email, passing first/last on signup, fix properties API
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed May 5, 2024
1 parent 90f91b3 commit 816713d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/cognito/customMessageSignUp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { formatEmail } from "../utils";

export const customMessageSignUp = async (event) => {
event.response.emailSubject = `Equalify Verification Code`;
event.response.emailMessage = formatEmail({ body: `<p>Hey there,</p><p>Your Equalify verification code is ${event.request.codeParameter}.</p><p>Thank you,<br/>Equalify` });
return event;
}
6 changes: 3 additions & 3 deletions src/cognito/postConfirmationConfirmSignUp.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { pgClient } from "../utils/index.js";

export const postConfirmationConfirmSignUp = async (event) => {
const { sub, email, name } = event.request.userAttributes;
const { sub, email, given_name, family_name } = event.request.userAttributes;
await pgClient.connect();
await pgClient.query(`
INSERT INTO "users" ("id", "email", "name") VALUES ($1, $2, $3)
`, [sub, email, name]);
INSERT INTO "users" ("id", "email", "first_name", "last_name") VALUES ($1, $2, $3, $4)
`, [sub, email, given_name, family_name]);
await pgClient.clean();
return event;
}
12 changes: 6 additions & 6 deletions src/routes/addProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const addProperties = async ({ request, reply }) => {
message: 'Property Name is required.',
}
}
else if (!request.body.propertyUrl) {
else if (!request.body.sitemapUrl) {
return {
status: 'error',
message: 'Property URL is required.',
message: 'Sitemap URL is required.',
}
}
else if (!request.body.propertyDiscovery) {
Expand All @@ -20,10 +20,10 @@ export const addProperties = async ({ request, reply }) => {
message: 'Property Discovery settings are required.',
}
}
else if (!validateUrl(request.body.propertyUrl)) {
else if (!validateUrl(request.body.sitemapUrl)) {
return {
status: 'error',
message: 'Property URL is not valid.',
message: 'Sitemap URL is not valid.',
}
}
else if (!validateDiscovery(request.body.propertyDiscovery)) {
Expand All @@ -35,8 +35,8 @@ export const addProperties = async ({ request, reply }) => {

await pgClient.connect();
const id = (await pgClient.query(`
INSERT INTO "properties" ("user_id", "name", "url", "discovery") VALUES ($1, $2, $3, $4) RETURNING "id"
`, [jwtClaims.sub, request.body.propertyName, request.body.propertyUrl, request.body.discovery])).rows?.[0]?.id;
INSERT INTO "properties" ("user_id", "name", "sitemapUrl", "discovery") VALUES ($1, $2, $3, $4) RETURNING "id"
`, [jwtClaims.sub, request.body.propertyName, request.body.sitemapUrl, request.body.discovery])).rows?.[0]?.id;
await pgClient.clean();

return {
Expand Down
5 changes: 3 additions & 2 deletions src/routes/getProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export const getProperties = async ({ request, reply }) => {
${request.query.propertyIds.split(',').map(obj => `"${obj}"`).join()}
]},` : ''}
${request.query.propertyDiscovery ? `propertyDiscovery: {eq: "${request.query.propertyDiscovery}"},` : ''}
${request.query.propertyUrls ? `url: {in: ${request.query.propertyUrls.split(',').map(obj => `"${obj}"`)}},` : ''}
${request.query.propertyUrls ? `sitemapUrl: {in: ${request.query.propertyUrls.split(',').map(obj => `"${obj}"`)}},` : ''}
}` : ''}
) {
nodes {
id
name
url
sitemapUrl
lastProcessed
archived
discovery
processed
Expand Down
12 changes: 6 additions & 6 deletions src/routes/updateProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export const updateProperties = async ({ request, reply }) => {
message: 'Property ID is not a valid UUID.',
}
}
else if (!(request.body.propertyName || request.body.propertyUrl || request.body.propertyDiscovery)) {
else if (!(request.body.propertyName || request.body.sitemapUrl || request.body.propertyDiscovery)) {
return {
status: 'error',
message: 'At least propertyName, propertyUrl, and/or propertyDiscovery are required.',
message: 'At least propertyName, sitemapUrl, and/or propertyDiscovery are required.',
}
}
else if (request.body.propertyUrl && !validateUrl(request.body.propertyUrl)) {
else if (request.body.sitemapUrl && !validateUrl(request.body.sitemapUrl)) {
return {
status: 'error',
message: 'PropertyUrl is not valid.',
message: 'sitemapUrl is not valid.',
}
}
else if (request.body.propertyDiscovery && !validateDiscovery(request.body.propertyDiscovery)) {
Expand All @@ -32,8 +32,8 @@ export const updateProperties = async ({ request, reply }) => {
SELECT * FROM "properties" WHERE "id"=$1 AND "user_id"=$2
`, [request.body.propertyId, jwtClaims.sub]))?.rows?.[0];
await pgClient.query(`
UPDATE "properties" SET "name"=$1, "url"=$2, "discovery"=$3, "archived"=$4, "processed"=$5 WHERE "id"=$6 AND "user_id"=$7
`, [request.body.propertyName ?? original.name, request.body.propertyUrl ?? original.url, request.body.propertyDiscovery ?? original.discovery, request.body.propertyArchived ?? original.archived, request.body.propertyProcessed ?? original.processed, request.body.propertyId, jwtClaims.sub]);
UPDATE "properties" SET "name"=$1, "sitemapUrl"=$2, "discovery"=$3, "archived"=$4, "processed"=$5 WHERE "id"=$6 AND "user_id"=$7
`, [request.body.propertyName ?? original.name, request.body.sitemapUrl ?? original.sitemapUrl, request.body.propertyDiscovery ?? original.discovery, request.body.propertyArchived ?? original.archived, request.body.propertyProcessed ?? original.processed, request.body.propertyId, jwtClaims.sub]);
await pgClient.clean();

return {
Expand Down

0 comments on commit 816713d

Please sign in to comment.