Skip to content

Commit ae15189

Browse files
authored
Merge pull request #778 from podverse/v5-develop
Update to 5.1.16-alpha
2 parents 85235f2 + e3b8691 commit ae15189

File tree

10 files changed

+264
-29
lines changed

10 files changed

+264
-29
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "podverse-api",
3-
"version": "5.1.15-develop",
3+
"version": "5.1.16-develop",
44
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
55
"private": true,
66
"main": "./src/index.js",

src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { itemChapterRouter } from "./routes/itemChapter";
2828
import { mqRouter } from "./routes/mq";
2929
import { feedRouter } from "./routes/feed";
3030
import { publisherFeedRouter } from "./routes/publisherFeed";
31+
import { accountSettingsRouter } from "./routes/accountSettings";
3132

3233
export const app = express();
3334
const port = 1234;
@@ -65,6 +66,7 @@ export const startApp = async () => {
6566

6667
app.use(accountRouter);
6768
app.use(accountPayPalOrderRouter);
69+
app.use(accountSettingsRouter);
6870
app.use(authRouter);
6971
app.use(categoryRouter);
7072
app.use(channelRouter);

src/controllers/account/account.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import { sendEmailChangeVerificationEmail } from '@api/lib/mailer/sendChangeEmai
1616

1717
const createAccountSchema = Joi.object({
1818
email: Joi.string().email().required(),
19-
password: Joi.string().min(8).required()
19+
password: Joi.string().min(8).required(),
20+
locale: Joi.string().required()
2021
});
2122

2223
const updateAccountSchema = Joi.object({
2324
display_name: Joi.string().optional(),
2425
bio: Joi.string().optional(),
25-
sharable_status: Joi.number().valid(...Object.values(SharableStatusEnum)).optional()
26+
sharable_status: Joi.number().valid(...Object.values(SharableStatusEnum)).required(),
27+
locale: Joi.string().required()
2628
});
2729

2830
const sendVerificationEmailSchema = Joi.object({
@@ -70,8 +72,13 @@ const privateRelations = [
7072
'account_membership_status',
7173
'account_membership_status.account_membership',
7274
'account_notification_channels',
75+
'account_notification_channels.account_notification_channel_types',
7376
// 'account_paypal_orders',
7477
// 'account_reset_password',
78+
'account_settings',
79+
'account_settings.account_settings_notification',
80+
'account_settings.account_settings_notification.account_settings_notification_types',
81+
// 'account_up_device_tokens',
7582
// 'account_up_devices',
7683
// 'account_verification'
7784
];
@@ -159,8 +166,8 @@ export class AccountController {
159166
static async create(req: Request, res: Response): Promise<void> {
160167
validateBodyObject(createAccountSchema, req, res, async () => {
161168
try {
162-
const { email, password } = req.body;
163-
await AccountController.accountService.create({ email, password });
169+
const { email, password, locale } = req.body as { email: string; password: string, locale: string };
170+
await AccountController.accountService.create({ email, password, locale });
164171
await AccountController.sendVerificationEmailHelper(email);
165172
res.json({
166173
message: 'Account created'
@@ -182,8 +189,13 @@ export class AccountController {
182189
validateBodyObject(updateAccountSchema, req, res, async () => {
183190
try {
184191
const account_id = req.user!.id;
185-
const dto = req.body;
186-
192+
const dto = req.body as {
193+
display_name?: string;
194+
bio?: string;
195+
sharable_status: SharableStatusEnum,
196+
locale: string
197+
};
198+
187199
const updatedAccount = await AccountController.accountService.update(account_id, dto);
188200
res.json(updatedAccount);
189201
} catch (error) {
Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
import { Request, Response } from 'express';
22
import Joi from 'joi';
3+
import { ACCOUNT_FCM_DEVICE_PLATFORM_VALUES, AccountFCMDevicePlatformValues } from 'podverse-helpers';
34
import { AccountFCMDeviceService } from 'podverse-orm';
45
import { handleGenericErrorResponse } from '@api/controllers/helpers/error';
56
import { validateBodyObject } from '@api/lib/validation';
67
import { ensureAuthenticated } from '@api/lib/auth';
78

89
const createAccountFCMDeviceSchema = Joi.object({
9-
fcm_token: Joi.string().required()
10+
fcm_token: Joi.string().required(),
11+
installation_id: Joi.string().required(),
12+
platform: Joi.string().valid(...ACCOUNT_FCM_DEVICE_PLATFORM_VALUES).required()
1013
});
1114

1215
const updateAccountFCMDeviceSchema = Joi.object({
13-
previous_fcm_token: Joi.string().required(),
14-
new_fcm_token: Joi.string().required()
16+
new_fcm_token: Joi.string().required(),
17+
installation_id: Joi.string().required(),
18+
previous_fcm_token: Joi.string().required().allow(null),
19+
platform: Joi.string().valid(...ACCOUNT_FCM_DEVICE_PLATFORM_VALUES).required()
1520
});
1621

1722
const deleteAccountFCMDeviceSchema = Joi.object({
18-
account_id: Joi.string().required(),
19-
fcm_token: Joi.string().required()
23+
fcm_token: Joi.string().required().allow(null),
24+
installation_id: Joi.string().required().allow(null),
2025
});
2126

22-
class AccountFCMDeviceController {
27+
const updateLocaleForAccountSchema = Joi.object({
28+
locale: Joi.string().required()
29+
});
30+
31+
export class AccountFCMDeviceController {
2332
private static accountFCMDeviceService = new AccountFCMDeviceService();
2433

2534
static async create(req: Request, res: Response): Promise<void> {
2635
ensureAuthenticated(req, res, async () => {
2736
validateBodyObject(createAccountFCMDeviceSchema, req, res, async () => {
2837
try {
2938
const jwtUser = req.user!;
30-
const { fcm_token } = req.body;
31-
const accountFCMDevice = await AccountFCMDeviceController.accountFCMDeviceService.create(jwtUser.id, fcm_token);
39+
const { fcm_token, installation_id, platform } = req.body as {
40+
fcm_token: string;
41+
installation_id: string;
42+
platform: AccountFCMDevicePlatformValues;
43+
};
44+
const accountFCMDevice = await AccountFCMDeviceController
45+
.accountFCMDeviceService.create(jwtUser.id, {
46+
fcm_token,
47+
installation_id,
48+
platform
49+
});
3250
res.json(accountFCMDevice);
3351
} catch (error) {
3452
handleGenericErrorResponse(res, error);
@@ -42,8 +60,19 @@ class AccountFCMDeviceController {
4260
validateBodyObject(updateAccountFCMDeviceSchema, req, res, async () => {
4361
try {
4462
const jwtUser = req.user!;
45-
const { previous_fcm_token, new_fcm_token } = req.body;
46-
const accountFCMDevice = await AccountFCMDeviceController.accountFCMDeviceService.update(jwtUser.id, previous_fcm_token, new_fcm_token);
63+
const { previous_fcm_token, new_fcm_token, installation_id, platform } = req.body as {
64+
new_fcm_token: string;
65+
installation_id: string;
66+
previous_fcm_token: string | null;
67+
platform: AccountFCMDevicePlatformValues;
68+
};
69+
const accountFCMDevice = await AccountFCMDeviceController
70+
.accountFCMDeviceService.update(jwtUser.id, {
71+
new_fcm_token,
72+
installation_id,
73+
previous_fcm_token,
74+
platform
75+
});
4776
res.json(accountFCMDevice);
4877
} catch (error) {
4978
handleGenericErrorResponse(res, error);
@@ -57,15 +86,47 @@ class AccountFCMDeviceController {
5786
validateBodyObject(deleteAccountFCMDeviceSchema, req, res, async () => {
5887
try {
5988
const jwtUser = req.user!;
60-
const { fcm_token } = req.body;
61-
await AccountFCMDeviceController.accountFCMDeviceService.delete(jwtUser.id, fcm_token);
89+
const { fcm_token, installation_id } = req.body as {
90+
fcm_token: string | null;
91+
installation_id: string | null;
92+
};
93+
await AccountFCMDeviceController
94+
.accountFCMDeviceService.delete(jwtUser.id, {
95+
fcm_token: fcm_token ?? null,
96+
installation_id: installation_id ?? null
97+
});
6298
res.json({ message: 'FCM device deleted successfully' });
6399
} catch (error) {
64100
handleGenericErrorResponse(res, error);
65101
}
66102
});
67103
});
68104
}
69-
}
70105

71-
export { AccountFCMDeviceController };
106+
static async getAllForAccount(req: Request, res: Response): Promise<void> {
107+
ensureAuthenticated(req, res, async () => {
108+
try {
109+
const jwtUser = req.user!;
110+
const devices = await AccountFCMDeviceController.accountFCMDeviceService.getAllForAccount(jwtUser.id);
111+
res.json(devices);
112+
} catch (error) {
113+
handleGenericErrorResponse(res, error);
114+
}
115+
});
116+
}
117+
118+
static async updateLocaleForAccount(req: Request, res: Response): Promise<void> {
119+
ensureAuthenticated(req, res, async () => {
120+
validateBodyObject(updateLocaleForAccountSchema, req, res, async () => {
121+
try {
122+
const jwtUser = req.user!;
123+
const { locale } = req.body as { locale: string };
124+
await AccountFCMDeviceController.accountFCMDeviceService.updateLocaleForAccount(jwtUser.id, { locale });
125+
res.json({ message: 'Locale updated for account devices' });
126+
} catch (error) {
127+
handleGenericErrorResponse(res, error);
128+
}
129+
});
130+
});
131+
}
132+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Request, Response } from 'express';
2+
import { AccountNotificationChannelTypeService } from 'podverse-orm';
3+
import Joi from 'joi';
4+
import { ACCOUNT_NOTIFICATION_TYPE_VALUES, AccountNotificationTypeEnum } from 'podverse-helpers';
5+
import { ensureAuthenticated } from '@api/lib/auth';
6+
import { handleGenericErrorResponse } from '../helpers/error';
7+
import { validateBodyObject, validateParamsObject } from '@api/lib/validation';
8+
9+
const createNotificationChannelTypeSchema = Joi.object({
10+
channel_id_text: Joi.string().required(),
11+
type: Joi.string().valid(...ACCOUNT_NOTIFICATION_TYPE_VALUES).required()
12+
});
13+
14+
const deleteNotificationChannelTypeSchema = Joi.object({
15+
channel_id_text: Joi.string().required(),
16+
type: Joi.string().valid(...ACCOUNT_NOTIFICATION_TYPE_VALUES).required()
17+
});
18+
19+
class AccountNotificationChannelTypeController {
20+
private static accountNotificationChannelTypeService = new AccountNotificationChannelTypeService();
21+
22+
static async create(req: Request, res: Response): Promise<void> {
23+
ensureAuthenticated(req, res, async () => {
24+
validateBodyObject(createNotificationChannelTypeSchema, req, res, async () => {
25+
try {
26+
const jwtUser = req.user!;
27+
const { channel_id_text, type } = req.body as { channel_id_text: string; type: AccountNotificationTypeEnum };
28+
const notificationChannelType = await AccountNotificationChannelTypeController
29+
.accountNotificationChannelTypeService.create(jwtUser.id, channel_id_text, type);
30+
res.status(201).json(notificationChannelType);
31+
} catch (err) {
32+
handleGenericErrorResponse(res, err);
33+
}
34+
});
35+
});
36+
}
37+
38+
static async delete(req: Request, res: Response): Promise<void> {
39+
ensureAuthenticated(req, res, async () => {
40+
validateParamsObject(deleteNotificationChannelTypeSchema, req, res, async () => {
41+
try {
42+
const jwtUser = req.user!;
43+
const { channel_id_text, type } = req.params as { channel_id_text: string; type: AccountNotificationTypeEnum };
44+
await AccountNotificationChannelTypeController
45+
.accountNotificationChannelTypeService.delete(jwtUser.id, channel_id_text, type);
46+
res.status(204).end();
47+
} catch (err) {
48+
handleGenericErrorResponse(res, err);
49+
}
50+
});
51+
});
52+
}
53+
}
54+
55+
export { AccountNotificationChannelTypeController };
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Joi from 'joi';
2+
import { Request, Response } from 'express';
3+
import { AccountSettingsLocaleService } from 'podverse-orm';
4+
import { validateBodyObject } from '@api/lib/validation';
5+
import { ensureAuthenticated } from '@api/lib/auth';
6+
import { handleGenericErrorResponse } from '@api/controllers/helpers/error';
7+
8+
const createAccountSettingsLocaleSchema = Joi.object({
9+
locale: Joi.string().required()
10+
});
11+
12+
const updateAccountSettingsLocaleSchema = Joi.object({
13+
locale: Joi.string().required()
14+
});
15+
16+
export class AccountSettingsLocaleController {
17+
18+
static async update(req: Request, res: Response): Promise<void> {
19+
validateBodyObject(updateAccountSettingsLocaleSchema, req, res, async () => {
20+
ensureAuthenticated(req, res, async () => {
21+
try {
22+
const account_id = req.user!.id;
23+
const { locale } = req.body;
24+
const service = new AccountSettingsLocaleService();
25+
const updated = await service.update({ account_id, locale });
26+
res.json({ data: updated });
27+
} catch (error) {
28+
handleGenericErrorResponse(res, error);
29+
}
30+
});
31+
});
32+
}
33+
34+
}

0 commit comments

Comments
 (0)