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

create synonym group for eventId if none exists #2642

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions app/email-incoming/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import { sendEmail } from '~/lib/email.server'
import { hostname, origin } from '~/lib/env.server'
import { putRaw, submitterGroup } from '~/routes/circulars/circulars.server'
import {

Check warning on line 30 in app/email-incoming/circulars/index.ts

View check run for this annotation

Codecov / codecov/patch

app/email-incoming/circulars/index.ts#L30

Added line #L30 was not covered by tests
createSynonyms,
synonymExists,
} from '~/routes/synonyms/synonyms.server'

interface UserData {
email: string
Expand Down Expand Up @@ -99,6 +103,8 @@
// Removes sub as a property if it is undefined from the legacy users
if (!circular.sub) delete circular.sub
const { circularId } = await putRaw(circular)
if (eventId && !(await synonymExists({ eventId })))
await createSynonyms([eventId])

Check warning on line 107 in app/email-incoming/circulars/index.ts

View check run for this annotation

Codecov / codecov/patch

app/email-incoming/circulars/index.ts#L107

Added line #L107 was not covered by tests

// Send a success email
await sendSuccessEmail({
Expand Down
7 changes: 5 additions & 2 deletions app/routes/circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { dedent } from 'ts-dedent'

import { type User, getUser } from '../_auth/user.server'
import { createSynonyms, synonymExists } from '../synonyms/synonyms.server'

Check warning on line 25 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L25

Added line #L25 was not covered by tests
import {
bodyIsValid,
formatAuthor,
Expand Down Expand Up @@ -311,8 +312,10 @@

const eventId = parseEventFromSubject(item.subject)
if (eventId) circular.eventId = eventId

return await putRaw(circular)
const result = await putRaw(circular)

Check warning on line 315 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L315

Added line #L315 was not covered by tests
if (eventId && !(await synonymExists({ eventId })))
await createSynonyms([eventId])
return result

Check warning on line 318 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L317-L318

Added lines #L317 - L318 were not covered by tests
}

export async function circularRedirect(query: string) {
Expand Down
14 changes: 14 additions & 0 deletions app/routes/synonyms/synonyms.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@
return Items as Circular[]
}

export async function synonymExists({ eventId }: { eventId: string }) {
const db = await tables()
const { Items } = await db.synonyms.query({

Check warning on line 127 in app/routes/synonyms/synonyms.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms/synonyms.server.ts#L126-L127

Added lines #L126 - L127 were not covered by tests
KeyConditionExpression: '#eventId = :eventId',
ExpressionAttributeNames: {
'#eventId': 'eventId',
},
ExpressionAttributeValues: {
':eventId': eventId,
},
})
return Items.length >= 1

Check warning on line 136 in app/routes/synonyms/synonyms.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/synonyms/synonyms.server.ts#L136

Added line #L136 was not covered by tests
}

/*
* If an eventId already has a synonym and is passed in, it will unlink the
* eventId from the old synonym and the only remaining link will be to the
Expand Down
Loading