add notifications to mothership

This commit is contained in:
Ben Allfree 2024-01-10 10:07:01 +00:00
parent abd6261233
commit 6c1695d035
9 changed files with 418 additions and 0 deletions

View File

@ -0,0 +1,49 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const collection = new Collection({
"id": "y5lqraz7c4jvisu",
"created": "2024-01-08 13:55:45.485Z",
"updated": "2024-01-08 13:55:45.485Z",
"name": "notifications",
"type": "base",
"system": false,
"schema": [
{
"system": false,
"id": "ezyqswtg",
"name": "payload",
"type": "json",
"required": true,
"presentable": false,
"unique": false,
"options": {
"maxSize": 2000000
}
},
{
"system": false,
"id": "as9ni2h6",
"name": "delivered",
"type": "bool",
"required": false,
"presentable": false,
"unique": false,
"options": {}
}
],
"indexes": [],
"listRule": null,
"viewRule": null,
"createRule": null,
"updateRule": null,
"deleteRule": null,
"options": {}
});
return Dao(db).saveCollection(collection);
}, (db) => {
const dao = new Dao(db);
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu");
return dao.deleteCollection(collection);
})

View File

@ -0,0 +1,96 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "ry5pnrld",
"name": "user",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "systemprofiles0",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "fksunfv1",
"name": "instance",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "etae8tuiaxl6xfv",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "gmqwgamf",
"name": "campaign",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "yfhnigik0uvyt4m",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "crksfxsv",
"name": "message",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "w1vjr1edr5tsam3",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("ry5pnrld")
// remove
collection.schema.removeField("fksunfv1")
// remove
collection.schema.removeField("gmqwgamf")
// remove
collection.schema.removeField("crksfxsv")
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,33 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "dwn9j8oo",
"name": "channel",
"type": "select",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSelect": 1,
"values": [
"email",
"lemonbot"
]
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("dwn9j8oo")
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,45 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("as9ni2h6")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "sgeq9rbv",
"name": "delivered",
"type": "date",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": "",
"max": ""
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "as9ni2h6",
"name": "delivered",
"type": "bool",
"required": false,
"presentable": false,
"unique": false,
"options": {}
}))
// remove
collection.schema.removeField("sgeq9rbv")
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,33 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "cmkxbt9j",
"name": "payment",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "iff2jfzb89dwiov",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("cmkxbt9j")
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,69 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "qoshryii",
"name": "sent_message",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "18rfmj8aklx6bjq",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "crksfxsv",
"name": "campaign_message",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "w1vjr1edr5tsam3",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("qoshryii")
// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "crksfxsv",
"name": "message",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "w1vjr1edr5tsam3",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,33 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "v8zn89fa",
"name": "message_template",
"type": "relation",
"required": true,
"presentable": false,
"unique": false,
"options": {
"collectionId": "6m8h2sy0nutig46",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("v8zn89fa")
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,29 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// add
collection.schema.addField(new SchemaField({
"system": false,
"id": "zoqchc2l",
"name": "message_template_vars",
"type": "json",
"required": true,
"presentable": false,
"unique": false,
"options": {
"maxSize": 2000000
}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("y5lqraz7c4jvisu")
// remove
collection.schema.removeField("zoqchc2l")
return dao.saveCollection(collection)
})

View File

@ -0,0 +1,31 @@
/// <reference path="../types/types.d.ts" />
routerAdd(`GET`, `api/process_single_notification`, (c) => {
const { mkLog, processNotification } = /** @type {Lib} */ (
require(`${__hooks}/lib.js`)
)
const log = mkLog(`process_single_notification`)
log(`start`)
try {
const notification = $app
.dao()
.findFirstRecordByData(`notifications`, `delivered`, ``)
if (!notification) {
return c.json(200, `No notifications to send`)
}
processNotification(notification, { log, test: true })
} catch (e) {
c.json(500, `${e}`)
}
return c.json(200, { status: 'ok' })
})
onModelAfterCreate((e) => {
const { processNotification, mkLog } = /** @type {Lib} */ (
require(`${__hooks}/lib.js`)
)
const log = mkLog(`notification:afterCreate`)
log(`start`)
// processNotification(e.model, { log })
}, `notifications`)