-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Automatically created by 'sqlite auto migrator (SAM)' on 2024-04-28T18:51:38.159Z | ||
|
||
import { Database } from 'sqlite-auto-migrator'; | ||
|
||
// Pragmas can't be changed in transactions, so they are tracked separately. | ||
// Note that most pragmas are not persisted in the database file and will have to be set on each new connection. | ||
export const PRAGMAS = {"analysis_limit":0,"application_id":0,"auto_vacuum":0,"automatic_index":1,"timeout":1000,"cache_size":-2000,"cache_spill":483,"cell_size_check":0,"checkpoint_fullfsync":0,"seq":0,"name":"Records","compile_options":"ATOMIC_INTRINSICS=1","count_changes":0,"data_version":1,"file":"","defer_foreign_keys":0,"empty_result_callbacks":0,"encoding":"UTF-8","foreign_keys":0,"freelist_count":0,"full_column_names":0,"fullfsync":0,"builtin":1,"type":"table","enc":"utf8","narg":2,"flags":2099200,"hard_heap_limit":0,"ignore_check_constraints":0,"integrity_check":"ok","journal_mode":"delete","journal_size_limit":-1,"legacy_alter_table":0,"locking_mode":"normal","max_page_count":1073741823,"page_count":12,"page_size":4096,"query_only":0,"quick_check":"ok","read_uncommitted":0,"recursive_triggers":0,"reverse_unordered_selects":0,"schema_version":5,"secure_delete":0,"short_column_names":1,"soft_heap_limit":0,"synchronous":2,"schema":"main","ncol":5,"wr":0,"strict":0,"temp_store":0,"threads":0,"trusted_schema":1,"user_version":0,"wal_autocheckpoint":1000,"busy":0,"log":-1,"checkpointed":-1,"writable_schema":0}; | ||
|
||
/** | ||
* Runs the necessary SQL commands to migrate the database up to this version from the previous version. | ||
* Automatically runs in a transaction with deferred foreign keys. | ||
* @param {Database} db database instance to run SQL commands on | ||
*/ | ||
export async function up(db) { | ||
await db.run("ALTER TABLE \"businesses\" ADD COLUMN \"absentemail\" INTEGER DEFAULT 1"); | ||
} | ||
|
||
/** | ||
* Runs the necessary SQL commands to migrate the database down to the previous version from this version. | ||
* Automatically runs in a transaction with deferred foreign keys. | ||
* @param {Database} db database instance to run SQL commands on | ||
*/ | ||
export async function down(db) { | ||
await db.run("ALTER TABLE \"businesses\" DROP COLUMN \"absentemail\""); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Automatically created by 'sqlite auto migrator (SAM)' on 2024-04-28T18:51:51.161Z | ||
|
||
import { Database } from 'sqlite-auto-migrator'; | ||
|
||
// Pragmas can't be changed in transactions, so they are tracked separately. | ||
// Note that most pragmas are not persisted in the database file and will have to be set on each new connection. | ||
export const PRAGMAS = {"analysis_limit":0,"application_id":0,"auto_vacuum":0,"automatic_index":1,"timeout":1000,"cache_size":-2000,"cache_spill":483,"cell_size_check":0,"checkpoint_fullfsync":0,"seq":0,"name":"Records","compile_options":"ATOMIC_INTRINSICS=1","count_changes":0,"data_version":1,"file":"","defer_foreign_keys":0,"empty_result_callbacks":0,"encoding":"UTF-8","foreign_keys":0,"freelist_count":0,"full_column_names":0,"fullfsync":0,"builtin":1,"type":"table","enc":"utf8","narg":2,"flags":2099200,"hard_heap_limit":0,"ignore_check_constraints":0,"integrity_check":"ok","journal_mode":"delete","journal_size_limit":-1,"legacy_alter_table":0,"locking_mode":"normal","max_page_count":1073741823,"page_count":12,"page_size":4096,"query_only":0,"quick_check":"ok","read_uncommitted":0,"recursive_triggers":0,"reverse_unordered_selects":0,"schema_version":5,"secure_delete":0,"short_column_names":1,"soft_heap_limit":0,"synchronous":2,"schema":"main","ncol":5,"wr":0,"strict":0,"temp_store":0,"threads":0,"trusted_schema":1,"user_version":0,"wal_autocheckpoint":1000,"busy":0,"log":-1,"checkpointed":-1,"writable_schema":0}; | ||
|
||
/** | ||
* Runs the necessary SQL commands to migrate the database up to this version from the previous version. | ||
* Automatically runs in a transaction with deferred foreign keys. | ||
* @param {Database} db database instance to run SQL commands on | ||
*/ | ||
export async function up(db) { | ||
await db.run("CREATE TABLE temp_c7r62mgn8zu(id INTEGER PRIMARY KEY,name TEXT NOT NULL,joincode TEXT NOT NULL UNIQUE,subscriptionId TEXT NOT NULL UNIQUE,requireJoin INTEGER DEFAULT 0 NOT NULL,absentEmail INTEGER DEFAULT 1 NOT NULL)"); | ||
await db.run("INSERT INTO temp_c7r62mgn8zu (\"id\", \"name\", \"joincode\", \"subscriptionid\", \"requirejoin\", \"absentemail\") SELECT \"id\", \"name\", \"joincode\", \"subscriptionid\", \"requirejoin\", \"absentemail\" FROM \"businesses\""); | ||
await db.run("DROP TABLE \"businesses\""); | ||
await db.run("ALTER TABLE temp_c7r62mgn8zu RENAME TO \"businesses\""); | ||
} | ||
|
||
/** | ||
* Runs the necessary SQL commands to migrate the database down to the previous version from this version. | ||
* Automatically runs in a transaction with deferred foreign keys. | ||
* @param {Database} db database instance to run SQL commands on | ||
*/ | ||
export async function down(db) { | ||
await db.run("CREATE TABLE temp_c7r62mgn8zu(id INTEGER PRIMARY KEY,name TEXT NOT NULL,joincode TEXT NOT NULL UNIQUE,subscriptionId TEXT NOT NULL UNIQUE,requireJoin INTEGER DEFAULT 0 NOT NULL,absentemail INTEGER DEFAULT 1)"); | ||
await db.run("INSERT INTO temp_c7r62mgn8zu (\"id\", \"name\", \"joincode\", \"subscriptionid\", \"requirejoin\", \"absentemail\") SELECT \"id\", \"name\", \"joincode\", \"subscriptionid\", \"requirejoin\", \"absentemail\" FROM \"businesses\""); | ||
await db.run("DROP TABLE \"businesses\""); | ||
await db.run("ALTER TABLE temp_c7r62mgn8zu RENAME TO \"businesses\""); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { GET, PUT, sendGmail } from './util/Client.js'; | ||
import { requireLogin, getCurrentUser, requestGoogleCredential } from './util/Auth.js'; | ||
import { GET, PUT, sendEmail } from './util/Client.js'; | ||
import { requireLogin, getCurrentUser } from './util/Auth.js'; | ||
import { sanitizeText } from './util/util.js'; | ||
import { Popup } from './components/Popup.js'; | ||
const $ = window.$; | ||
|
@@ -147,44 +147,44 @@ window.markAbsent = async (businessId, eventId) => { | |
await Popup.alert(await res.text(), 'var(--error)'); | ||
return; | ||
} | ||
await Popup.alert( | ||
'You have been marked absent! Close this popup and click on your email account to send notifications to the event host(s).', | ||
'var(--success)', | ||
); | ||
await Popup.alert('You have been marked absent!', 'var(--success)'); | ||
|
||
// Send email notification to business owner and admins | ||
const credential = await requestGoogleCredential([ | ||
'https://www.googleapis.com/auth/gmail.send', | ||
]); | ||
let success = true; | ||
const res1 = await GET(`/businesses/${businessId}/writemembers`); | ||
const writeMembers = await res1.json(); | ||
console.log(writeMembers); | ||
// Send email notification to business owner and admins if setting is enabled | ||
const absentEmail = await GET(`/businesses/${businessId}/settings/absentemail`).then(res => | ||
This comment has been minimized.
Sorry, something went wrong.
SanderGi
Collaborator
|
||
res.json(), | ||
); | ||
if (absentEmail.absentEmail === 1) { | ||
let success = true; | ||
const res1 = await GET(`/businesses/${businessId}/writemembers`); | ||
const writeMembers = await res1.json(); | ||
|
||
for (const member of writeMembers) { | ||
const res = await sendGmail( | ||
member.email, | ||
'Attendance Scanner Notification of Absence', | ||
'Hi ' + | ||
member.name + | ||
',\n\n' + | ||
user.name + | ||
' has marked themselves absent from the event.\n\n(automatically sent via Attendance Scanner QR)', | ||
credential, | ||
); | ||
if (!res.ok) { | ||
success = false; | ||
const obj = await res.json(); | ||
const message = obj.error.message; | ||
for (const member of writeMembers) { | ||
const res = await sendEmail( | ||
member.email, | ||
'Attendance Scanner Notification of Absence', | ||
'Hi ' + | ||
member.name + | ||
',\n\n' + | ||
user.name + | ||
' has marked themselves absent from the event.\n\n(automatically sent via Attendance Scanner QR)', | ||
); | ||
if (!res.ok) { | ||
success = false; | ||
const obj = await res.json(); | ||
const message = obj.error.message; | ||
Popup.alert( | ||
`Email to ${sanitizeText(member[1])} failed to send. ` + message, | ||
'var(--error)', | ||
); | ||
} | ||
} | ||
if (success) { | ||
Popup.alert( | ||
`Email to ${sanitizeText(member[1])} failed to send. ` + message, | ||
'var(--error)', | ||
'An email has been sent, notifying event host(s) of your absence', | ||
'var(--success)', | ||
); | ||
} | ||
} | ||
if (success) { | ||
Popup.alert('Emails sent successfully!', 'var(--success)'); | ||
} | ||
|
||
// manually change html since evo-calendar is broken when adding/removing or updating events | ||
const badge = document.createElement('span'); | ||
|
Don't forget to squash migrations when you make multiple schema changes in the same commit. I've done it for you in this commit: e7121aa. We want to keep the migrations as few as possible to make them easier to work with in case we need to (also fewer migrations is always going to be faster to execute). All you need to do is delete the migration files you've added and a new equivalent one will be created while npm run dev is active