11 Commits
1.1.1 ... 1.1.3

Author SHA1 Message Date
mrjvs
783d89492d Merge pull request #18 from movie-web/dev
Version 1.1.3: Add endpoint to edit device name
2023-11-24 20:07:57 +01:00
mrjvs
4663b2c1f7 Merge branch 'master' into dev 2023-11-24 20:06:42 +01:00
William Oldham
ceea274e70 Merge pull request #17 from movie-web/device-name-update
Device name update + fixing settings endpoint
2023-11-24 18:56:08 +00:00
William Oldham
6d2dcd04e9 Apply suggestions from code review 2023-11-24 18:55:20 +00:00
mrjvs
8a3c0d6edb add settings nullable + undefined difference 2023-11-24 18:40:54 +01:00
mrjvs
72657e73c8 add update session endpoint 2023-11-24 18:00:06 +01:00
William Oldham
1bb344ec2f Merge pull request #16 from movie-web/dev
v1.1.2: Fix Settings
2023-11-22 23:23:00 +00:00
William Oldham
b30623c483 Merge pull request #15 from movie-web/fix-user-settings
Fix user settings
2023-11-22 23:21:26 +00:00
William Oldham
233cb11ac6 Bump version 2023-11-22 23:17:29 +00:00
William Oldham
d3aa4847f8 Update UserSettings primary key to text, to match user 2023-11-22 23:17:29 +00:00
William Oldham
4bf2e658f7 Fix ESLint Ignore for migrations 2023-11-22 23:17:29 +00:00
7 changed files with 56 additions and 15 deletions

View File

@@ -13,7 +13,7 @@ module.exports = {
sourceType: 'module', sourceType: 'module',
}, },
plugins: ['@typescript-eslint'], plugins: ['@typescript-eslint'],
ignorePatterns: ['./src/db/migrations/**/*'], ignorePatterns: ['src/db/migrations/**/*'],
rules: { rules: {
'@typescript-eslint/interface-name-prefix': 'off', '@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-function-return-type': 'off',

View File

@@ -1,6 +1,6 @@
{ {
"name": "backend", "name": "backend",
"version": "1.1.1", "version": "1.1.3",
"private": true, "private": true,
"homepage": "https://github.com/movie-web/backend", "homepage": "https://github.com/movie-web/backend",
"engines": { "engines": {

View File

@@ -587,12 +587,12 @@
"columns": { "columns": {
"id": { "id": {
"name": "id", "name": "id",
"type": "uuid", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": false, "nullable": false,
"mappedType": "uuid" "mappedType": "text"
}, },
"application_theme": { "application_theme": {
"name": "application_theme", "name": "application_theme",

View File

@@ -0,0 +1,14 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20231122231620 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "user_settings" alter column "id" type text using ("id"::text);');
}
async down(): Promise<void> {
this.addSql('alter table "user_settings" alter column "id" drop default;');
this.addSql('alter table "user_settings" alter column "id" type uuid using ("id"::text::uuid);');
}
}

View File

@@ -1,10 +1,9 @@
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'; import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
import { randomUUID } from 'crypto';
@Entity({ tableName: 'user_settings' }) @Entity({ tableName: 'user_settings' })
export class UserSettings { export class UserSettings {
@PrimaryKey({ name: 'id', type: 'uuid' }) @PrimaryKey({ name: 'id', type: 'text' })
id: string = randomUUID(); id!: string;
@Property({ name: 'application_theme', nullable: true }) @Property({ name: 'application_theme', nullable: true })
applicationTheme?: string | null; applicationTheme?: string | null;

View File

@@ -1,4 +1,4 @@
import { Session } from '@/db/models/Session'; import { Session, formatSession } from '@/db/models/Session';
import { StatusError } from '@/services/error'; import { StatusError } from '@/services/error';
import { handle } from '@/services/handler'; import { handle } from '@/services/handler';
import { makeRouter } from '@/services/router'; import { makeRouter } from '@/services/router';
@@ -32,4 +32,32 @@ export const sessionRouter = makeRouter((app) => {
}; };
}), }),
); );
app.patch(
'/sessions/:sid',
{
schema: {
params: z.object({
sid: z.string(),
}),
body: z.object({
deviceName: z.string().min(1).optional(),
}),
},
},
handle(async ({ auth, params, body, em }) => {
await auth.assert();
const targetedSession = await em.findOne(Session, { id: params.sid });
if (!targetedSession) throw new StatusError('Not found', 404);
if (targetedSession.id !== params.sid)
throw new StatusError('Cannot edit sessions other than your own', 401);
if (body.deviceName) targetedSession.device = body.deviceName;
await em.persistAndFlush(targetedSession);
return formatSession(targetedSession);
}),
);
}); });

View File

@@ -38,9 +38,9 @@ export const userSettingsRouter = makeRouter((app) => {
uid: z.string(), uid: z.string(),
}), }),
body: z.object({ body: z.object({
applicationLanguage: z.string().optional(), applicationLanguage: z.string().nullable().optional(),
applicationTheme: z.string().optional(), applicationTheme: z.string().nullable().optional(),
defaultSubtitleLanguage: z.string().optional(), defaultSubtitleLanguage: z.string().nullable().optional(),
}), }),
}, },
}, },
@@ -58,12 +58,12 @@ export const userSettingsRouter = makeRouter((app) => {
settings.id = params.uid; settings.id = params.uid;
} }
if (body.applicationLanguage) if (body.applicationLanguage !== undefined)
settings.applicationLanguage = body.applicationLanguage; settings.applicationLanguage = body.applicationLanguage;
if (body.applicationTheme) if (body.defaultSubtitleLanguage !== undefined)
settings.applicationTheme = body.applicationTheme;
if (body.defaultSubtitleLanguage)
settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage; settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage;
if (body.applicationTheme !== undefined)
settings.applicationTheme = body.applicationTheme;
await em.persistAndFlush(settings); await em.persistAndFlush(settings);
return formatUserSettings(settings); return formatUserSettings(settings);