Skip to content

Commit 13b2046

Browse files
author
Ajit Kumar
committed
fix(sponsor api)
1 parent 697217c commit 13b2046

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

server/apis/sponsor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Sponsor = require('../entities/sponsor');
44
const { resolve } = require('node:path');
55
const { existsSync } = require('node:fs');
66
const { google } = require('googleapis');
7+
const moment = require('moment');
78
const { getLoggedInUser, sendNotification } = require('../lib/helpers');
89

910
const router = Router();
@@ -18,6 +19,7 @@ router.get('/', async (req, res) => {
1819
[
1920
[Sponsor.STATUS, Sponsor.STATE_PURCHASED],
2021
[Sponsor.PUBLIC, 1],
22+
[Sponsor.CREATED_AT, moment().add(-30, 'days').toISOString(), '>'],
2123
],
2224
{ page, limit },
2325
);
@@ -60,7 +62,10 @@ router.post('/', async (req, res) => {
6062
await mkdir(sponsorImagesPath, { recursive: true });
6163
}
6264

63-
await writeFile(path, image.split(';base64,')[1], { encoding: 'base64' });
65+
if (image) {
66+
await writeFile(path, image.split(';base64,')[1], { encoding: 'base64' });
67+
}
68+
6469
await Sponsor.insert(
6570
[Sponsor.NAME, name],
6671
[Sponsor.TIER, tier],

server/entities/sponsor.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const table = `create table if not exists sponsor (
1111
package_name text,
1212
website text,
1313
image text,
14+
tagline text,
1415
tier text,
1516
public integer default 0,
1617
status integer default 2,
@@ -30,6 +31,7 @@ class Sponsor extends Entity {
3031
PUBLIC = 'public';
3132
USER_ID = 'user_id';
3233
WEBSITE = 'website';
34+
TAGLINE = 'tagline';
3335
ORDER_ID = 'order_id';
3436
CREATED_AT = 'created_at';
3537
PACKAGE_NAME = 'package_name';
@@ -53,6 +55,7 @@ class Sponsor extends Entity {
5355
this.AMOUNT,
5456
this.STATUS,
5557
this.PUBLIC,
58+
this.TAGLINE,
5659
this.WEBSITE,
5760
this.USER_ID,
5861
this.ORDER_ID,
@@ -62,7 +65,19 @@ class Sponsor extends Entity {
6265
}
6366

6467
get safeColumns() {
65-
return [this.ID, this.NAME, this.TIER, this.EMAIL, this.IMAGE, this.AMOUNT, this.STATUS, this.WEBSITE, this.CREATED_AT, this.PACKAGE_NAME];
68+
return [
69+
this.ID,
70+
this.NAME,
71+
this.TIER,
72+
this.EMAIL,
73+
this.TAGLINE,
74+
this.IMAGE,
75+
this.AMOUNT,
76+
this.STATUS,
77+
this.WEBSITE,
78+
this.CREATED_AT,
79+
this.PACKAGE_NAME,
80+
];
6681
}
6782
}
6883

updateSchema.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// biome-ignore lint/style/noCommonJs: can't use import
22
const db = require('./server/lib/db');
33

4-
const queries = [
5-
'ALTER TABLE plugin ADD COLUMN package_updated_at TIMESTAMP',
6-
'CREATE TRIGGER IF NOT EXISTS plugin_package_updated_at AFTER UPDATE ON plugin FOR EACH ROW WHEN old.version != new.version BEGIN UPDATE plugin SET package_updated_at = current_timestamp WHERE id = old.id; END;',
7-
];
4+
const queries = ['ALTER TABLE sponsor ADD COLUMN tagline TEXT'];
85

96
(async () => {
107
for (const query of queries) {

0 commit comments

Comments
 (0)