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

feat: add emails endpoints #47

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: add emails endpoints #47

wants to merge 5 commits into from

Conversation

kamilramocki
Copy link
Member

No description provided.

@kamilramocki kamilramocki added the enhancement New feature or request label Jan 6, 2025
@kamilramocki kamilramocki self-assigned this Jan 6, 2025
@kamilramocki kamilramocki linked an issue Jan 6, 2025 that may be closed by this pull request
Copy link
Member

@dawidlinek dawidlinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dzięki za sprawną robotę, kilka mniejszych komentarzy

Comment on lines 13 to 25
const emails = await Email.query()
.where('event_id', eventId)
.preload('participants', async (query) => {
await query.pivotColumns(['status'])
})

const emailSummaries = emails.map((email) => ({
id: email.id,
name: email.name,
pending: email.participants.filter((p) => p.$extras.pivot_status === 'pending').length,
sent: email.participants.filter((p) => p.$extras.pivot_status === 'sent').length,
failed: email.participants.filter((p) => p.$extras.pivot_status === 'failed').length,
}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilramocki spróbuj użyć withCount z custom query w którym podajesz status (albo może grupowanie tez zadziała?)
https://lucid.adonisjs.com/docs/model-query-builder#withcount

Comment on lines 38 to 52
if (data.trigger) {
const validTriggers = ['participant_registered', 'form_filled', 'attribute_changed']
if (!validTriggers.includes(data.trigger)) {
return response.status(400).send({ message: 'Invalid trigger provided.' })
}

if (
(data.trigger === 'form_filled' || data.trigger === 'attribute_changed') &&
!data.triggerValue
) {
return response
.status(400)
.send({ message: 'Trigger value is required for the selected trigger.' })
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Przenieśmy to do walidatora

Może się przydać: https://vinejs.dev/docs/conditional_validation#requiredwhen

* Create an email for a specific event
*/
async store({ params, request, response }: HttpContext) {
const eventId = Number(params.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myślę, że mimo wszystko powinniśmy sprawdzić czy dany event istnieje i wtedy może utworzyć event.related('emails').create(data)

Comment on lines 85 to 99
if (data.trigger) {
const validTriggers = ['participant_registered', 'form_filled', 'attribute_changed']
if (!validTriggers.includes(data.trigger)) {
return response.status(400).send({ message: 'Invalid trigger provided.' })
}

if (
(data.trigger === 'form_filled' || data.trigger === 'attribute_changed') &&
!data.triggerValue
) {
return response
.status(400)
.send({ message: 'Trigger value is required for the selected trigger.' })
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu może być ten sam walidator co wyżej

Comment on lines 58 to 83
const participant = await Participant.findOrFail(params.id);

const emailId = request.input('email_id') as number;

const pivotData = request.only(['send_at', 'send_by', 'status']) as {
send_at?: string;
send_by?: string;
status?: string;
};

await participant.related('emails').attach({ [emailId]: pivotData });
return response.status(201).send({ message: 'Email successfully attached.' });
}

/**
* Detach email from participant
*/
async detachEmail({ params, request, response }: HttpContext) {
const participant = await Participant.findOrFail(params.id);

const emailId = request.input('email_id') as number;

await participant.related('emails').detach([emailId]);
return response.status(200).send({ message: 'Email successfully detached.' });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To rozwiążemy potem, bo nie będzie czegoś takiego jak detach email, będzie sendEmail i jak już zostanie wysłany to nie można go usunąć

Copy link
Member

@dawidlinek dawidlinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilramocki już wygląda to dobrze. Jak zrobisz testy i dokumentację to będzie można mergować

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat/endpointy maili
2 participants