diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-12 14:09:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-12 14:12:14 +0200 |
commit | 16c016e8b1d5ca46343d3363f9a49e24c5d7c944 (patch) | |
tree | 157dfa22ac95bd76a411aaf78e4df17152530e1c /server/controllers/api | |
parent | 9a320a06b663a2e02c3156a07135f75f9e987b11 (diff) | |
download | PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.tar.gz PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.tar.zst PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.zip |
Stricter models typing
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users/index.ts | 22 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 4 |
3 files changed, 22 insertions, 13 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index c655d1648..f384f0f28 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -323,14 +323,20 @@ async function updateUser (req: express.Request, res: express.Response) { | |||
323 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) | 323 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) |
324 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role | 324 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role |
325 | 325 | ||
326 | if (body.password !== undefined) userToUpdate.password = body.password | 326 | const keysToUpdate: (keyof UserUpdate)[] = [ |
327 | if (body.email !== undefined) userToUpdate.email = body.email | 327 | 'password', |
328 | if (body.emailVerified !== undefined) userToUpdate.emailVerified = body.emailVerified | 328 | 'email', |
329 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota | 329 | 'emailVerified', |
330 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily | 330 | 'videoQuota', |
331 | if (body.role !== undefined) userToUpdate.role = body.role | 331 | 'videoQuotaDaily', |
332 | if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags | 332 | 'role', |
333 | if (body.pluginAuth !== undefined) userToUpdate.pluginAuth = body.pluginAuth | 333 | 'adminFlags', |
334 | 'pluginAuth' | ||
335 | ] | ||
336 | |||
337 | for (const key of keysToUpdate) { | ||
338 | if (body[key] !== undefined) userToUpdate.set(key, body[key]) | ||
339 | } | ||
334 | 340 | ||
335 | const user = await userToUpdate.save() | 341 | const user = await userToUpdate.save() |
336 | 342 | ||
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 4ed58f978..2c225315c 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -5,6 +5,7 @@ import * as parseTorrent from 'parse-torrent' | |||
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { getEnabledResolutions } from '@server/lib/config' | 6 | import { getEnabledResolutions } from '@server/lib/config' |
7 | import { setVideoTags } from '@server/lib/video' | 7 | import { setVideoTags } from '@server/lib/video' |
8 | import { FilteredModelAttributes } from '@server/types' | ||
8 | import { | 9 | import { |
9 | MChannelAccountDefault, | 10 | MChannelAccountDefault, |
10 | MThumbnail, | 11 | MThumbnail, |
@@ -15,7 +16,7 @@ import { | |||
15 | MVideoThumbnail, | 16 | MVideoThumbnail, |
16 | MVideoWithBlacklistLight | 17 | MVideoWithBlacklistLight |
17 | } from '@server/types/models' | 18 | } from '@server/types/models' |
18 | import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' | 19 | import { MVideoImportFormattable } from '@server/types/models/video/video-import' |
19 | import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' | 20 | import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' |
20 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 21 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
21 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 22 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
@@ -253,7 +254,9 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You | |||
253 | privacy: body.privacy || VideoPrivacy.PRIVATE, | 254 | privacy: body.privacy || VideoPrivacy.PRIVATE, |
254 | duration: 0, // duration will be set by the import job | 255 | duration: 0, // duration will be set by the import job |
255 | channelId: channelId, | 256 | channelId: channelId, |
256 | originallyPublishedAt: body.originallyPublishedAt || importData.originallyPublishedAt | 257 | originallyPublishedAt: body.originallyPublishedAt |
258 | ? new Date(body.originallyPublishedAt) | ||
259 | : importData.originallyPublishedAt | ||
257 | } | 260 | } |
258 | const video = new VideoModel(videoData) | 261 | const video = new VideoModel(videoData) |
259 | video.url = getLocalVideoActivityPubUrl(video) | 262 | video.url = getLocalVideoActivityPubUrl(video) |
@@ -317,7 +320,7 @@ async function insertIntoDB (parameters: { | |||
317 | previewModel: MThumbnail | 320 | previewModel: MThumbnail |
318 | videoChannel: MChannelAccountDefault | 321 | videoChannel: MChannelAccountDefault |
319 | tags: string[] | 322 | tags: string[] |
320 | videoImportAttributes: Partial<MVideoImport> | 323 | videoImportAttributes: FilteredModelAttributes<VideoImportModel> |
321 | user: MUser | 324 | user: MUser |
322 | }): Promise<MVideoImportFormattable> { | 325 | }): Promise<MVideoImportFormattable> { |
323 | const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters | 326 | const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index c32626d30..f5ce15074 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -308,7 +308,7 @@ async function addVideo (options: { | |||
308 | if (videoInfo.scheduleUpdate) { | 308 | if (videoInfo.scheduleUpdate) { |
309 | await ScheduleVideoUpdateModel.create({ | 309 | await ScheduleVideoUpdateModel.create({ |
310 | videoId: video.id, | 310 | videoId: video.id, |
311 | updateAt: videoInfo.scheduleUpdate.updateAt, | 311 | updateAt: new Date(videoInfo.scheduleUpdate.updateAt), |
312 | privacy: videoInfo.scheduleUpdate.privacy || null | 312 | privacy: videoInfo.scheduleUpdate.privacy || null |
313 | }, { transaction: t }) | 313 | }, { transaction: t }) |
314 | } | 314 | } |
@@ -435,7 +435,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
435 | if (videoInfoToUpdate.scheduleUpdate) { | 435 | if (videoInfoToUpdate.scheduleUpdate) { |
436 | await ScheduleVideoUpdateModel.upsert({ | 436 | await ScheduleVideoUpdateModel.upsert({ |
437 | videoId: videoInstanceUpdated.id, | 437 | videoId: videoInstanceUpdated.id, |
438 | updateAt: videoInfoToUpdate.scheduleUpdate.updateAt, | 438 | updateAt: new Date(videoInfoToUpdate.scheduleUpdate.updateAt), |
439 | privacy: videoInfoToUpdate.scheduleUpdate.privacy || null | 439 | privacy: videoInfoToUpdate.scheduleUpdate.privacy || null |
440 | }, { transaction: t }) | 440 | }, { transaction: t }) |
441 | } else if (videoInfoToUpdate.scheduleUpdate === null) { | 441 | } else if (videoInfoToUpdate.scheduleUpdate === null) { |