mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-12 04:15:39 +08:00
Revise landing messaging and add news feed
This commit is contained in:
38
server/utils/subscribers.ts
Normal file
38
server/utils/subscribers.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { UpdateSubscriber, UpdateSubscriberDocument } from '../models/UpdateSubscriber'
|
||||
|
||||
interface RegisterSubscriberOptions {
|
||||
email: string
|
||||
name?: string
|
||||
source?: string
|
||||
consentPrivacy: boolean
|
||||
consentMarketing: boolean
|
||||
}
|
||||
|
||||
export async function registerUpdateSubscriber(options: RegisterSubscriberOptions) {
|
||||
const { email, name, source = 'landing-updates', consentPrivacy, consentMarketing } = options
|
||||
const now = new Date()
|
||||
|
||||
const existing = await UpdateSubscriber.findOne({ email })
|
||||
|
||||
if (existing) {
|
||||
existing.name = name || existing.name
|
||||
existing.source = source || existing.source
|
||||
existing.consentPrivacy = existing.consentPrivacy || consentPrivacy
|
||||
existing.consentMarketing = existing.consentMarketing || consentMarketing
|
||||
existing.lastUpdatedAt = now
|
||||
await existing.save()
|
||||
return { created: false, document: existing as UpdateSubscriberDocument }
|
||||
}
|
||||
|
||||
const document = await UpdateSubscriber.create({
|
||||
email,
|
||||
name,
|
||||
source,
|
||||
consentPrivacy,
|
||||
consentMarketing,
|
||||
subscribedAt: now,
|
||||
lastUpdatedAt: now,
|
||||
})
|
||||
|
||||
return { created: true, document }
|
||||
}
|
||||
Reference in New Issue
Block a user