2 changed files with 247 additions and 0 deletions
@ -0,0 +1,124 @@ |
|||
// app/services/broadcast-show.ts
|
|||
// Copyright (C) 2025 DTP Technologies, LLC
|
|||
// All Rights Reserved
|
|||
|
|||
import mongoose, { Types } from "mongoose"; |
|||
|
|||
import BroadcastShow, { |
|||
BroadcastShowStatus, |
|||
IBroadcastShow, |
|||
} from "../models/broadcast-show.js"; |
|||
|
|||
import { |
|||
DtpPlatform, |
|||
DtpService, |
|||
DtpServiceUpdate, |
|||
WebError, |
|||
WebPaginationParameters, |
|||
} from "../../lib/dtplib.js"; |
|||
import TextService from "./text.js"; |
|||
|
|||
export interface BroadcastShowDefinition { |
|||
title: string; |
|||
description: string; |
|||
} |
|||
|
|||
export interface BroadcastShowLibrary { |
|||
shows: Array<IBroadcastShow>; |
|||
totalShowCount: number; |
|||
} |
|||
|
|||
export class BroadcastShowService extends DtpService { |
|||
populateBroadcastShow: Array<mongoose.PopulateOptions>; |
|||
|
|||
static get name() { |
|||
return "BroadcastShowService"; |
|||
} |
|||
static get slug() { |
|||
return "broadcastShow"; |
|||
} |
|||
|
|||
constructor(platform: DtpPlatform) { |
|||
super(platform, BroadcastShowService); |
|||
this.populateBroadcastShow = [ |
|||
{ |
|||
path: "recentEpisodes", |
|||
}, |
|||
]; |
|||
} |
|||
|
|||
async create(definition: BroadcastShowDefinition): Promise<IBroadcastShow> { |
|||
const textService = this.getService<TextService>("text"); |
|||
|
|||
const show = new BroadcastShow(); |
|||
show.status = BroadcastShowStatus.Offline; |
|||
show.title = textService.filter(definition.title); |
|||
show.description = textService.filter(definition.description); |
|||
await show.save(); |
|||
|
|||
return show.toObject(); |
|||
} |
|||
|
|||
async update( |
|||
show: IBroadcastShow | Types.ObjectId, |
|||
definition: BroadcastShowDefinition |
|||
): Promise<IBroadcastShow> { |
|||
const textService = this.getService<TextService>("text"); |
|||
|
|||
const update: DtpServiceUpdate = {}; |
|||
update.$set = {}; |
|||
|
|||
update.$set.title = textService.filter(definition.title); |
|||
update.$set.description = textService.filter(definition.description); |
|||
|
|||
const newShow = await BroadcastShow.findByIdAndUpdate(show._id, update, { |
|||
new: true, |
|||
populate: this.populateBroadcastShow, |
|||
}).lean(); |
|||
|
|||
if (!newShow) { |
|||
throw new WebError(404, "show does not exist"); |
|||
} |
|||
|
|||
return newShow; |
|||
} |
|||
|
|||
async getById(showId: Types.ObjectId): Promise<IBroadcastShow | null> { |
|||
const show = await BroadcastShow.findById(showId) |
|||
.populate(this.populateBroadcastShow) |
|||
.lean(); |
|||
return show; |
|||
} |
|||
|
|||
async getLive( |
|||
pagination: WebPaginationParameters |
|||
): Promise<BroadcastShowLibrary> { |
|||
const search = { status: BroadcastShowStatus.Live }; |
|||
|
|||
const shows = await BroadcastShow.find(search) |
|||
.sort({ created: -1 }) |
|||
.skip(pagination.skip) |
|||
.limit(pagination.cpp) |
|||
.populate(this.populateBroadcastShow) |
|||
.lean(); |
|||
|
|||
const totalShowCount = await BroadcastShow.countDocuments(search); |
|||
return { shows, totalShowCount }; |
|||
} |
|||
|
|||
async getAll( |
|||
pagination: WebPaginationParameters |
|||
): Promise<BroadcastShowLibrary> { |
|||
const shows = await BroadcastShow.find() |
|||
.sort({ created: -1 }) |
|||
.skip(pagination.skip) |
|||
.limit(pagination.cpp) |
|||
.populate(this.populateBroadcastShow) |
|||
.lean(); |
|||
|
|||
const totalShowCount = await BroadcastShow.estimatedDocumentCount(); |
|||
return { shows, totalShowCount }; |
|||
} |
|||
} |
|||
|
|||
export default BroadcastShowService; |
@ -0,0 +1,123 @@ |
|||
// app/services/episode.ts
|
|||
// Copyright (C) 2025 DTP Technologies, LLC
|
|||
// All Rights Reserved
|
|||
|
|||
import mongoose, { Types } from "mongoose"; |
|||
|
|||
import Episode, { EpisodeStatus, IEpisode } from "../models/episode.js"; |
|||
|
|||
import { |
|||
DtpPlatform, |
|||
DtpService, |
|||
DtpServiceUpdate, |
|||
WebError, |
|||
WebPaginationParameters, |
|||
} from "../../lib/dtplib.js"; |
|||
|
|||
import TextService from "./text.js"; |
|||
|
|||
export interface EpisodeDefinition { |
|||
title: string; |
|||
description: string; |
|||
} |
|||
|
|||
export interface EpisodeLibrary { |
|||
episodes: Array<IEpisode>; |
|||
totalEpisodeCount: number; |
|||
} |
|||
|
|||
export class EpisodeService extends DtpService { |
|||
populateEpisode: Array<mongoose.PopulateOptions>; |
|||
|
|||
static get name() { |
|||
return "EpisodeService"; |
|||
} |
|||
static get slug() { |
|||
return "episode"; |
|||
} |
|||
|
|||
constructor(platform: DtpPlatform) { |
|||
super(platform, EpisodeService); |
|||
this.populateEpisode = [ |
|||
{ |
|||
path: "show", |
|||
}, |
|||
{ |
|||
path: "video", |
|||
}, |
|||
{ |
|||
path: "feedItems", |
|||
}, |
|||
]; |
|||
} |
|||
|
|||
async create(definition: EpisodeDefinition): Promise<IEpisode> { |
|||
const textService = this.getService<TextService>("text"); |
|||
const NOW = new Date(); |
|||
|
|||
const episode = new Episode(); |
|||
episode.created = NOW; |
|||
episode.title = textService.filter(definition.title); |
|||
episode.description = textService.filter(definition.description); |
|||
await episode.save(); |
|||
|
|||
return episode.toObject(); |
|||
} |
|||
|
|||
async update( |
|||
episode: IEpisode | Types.ObjectId, |
|||
definition: EpisodeDefinition |
|||
): Promise<IEpisode> { |
|||
const textService = this.getService<TextService>("text"); |
|||
|
|||
const update: DtpServiceUpdate = {}; |
|||
update.$set = {}; |
|||
|
|||
update.$set.title = textService.filter(definition.title); |
|||
update.$set.description = textService.filter(definition.description); |
|||
|
|||
const newEpisode = await Episode.findByIdAndUpdate(episode._id, update, { |
|||
new: true, |
|||
populate: this.populateEpisode, |
|||
}).lean(); |
|||
if (!newEpisode) { |
|||
throw new WebError(404, "show does not exist"); |
|||
} |
|||
return newEpisode; |
|||
} |
|||
|
|||
async getById(episodeId: Types.ObjectId): Promise<IEpisode | null> { |
|||
const show = await Episode.findById(episodeId) |
|||
.populate(this.populateEpisode) |
|||
.lean(); |
|||
return show; |
|||
} |
|||
|
|||
async getLive(pagination: WebPaginationParameters): Promise<EpisodeLibrary> { |
|||
const search = { status: EpisodeStatus.Live }; |
|||
|
|||
const episodes = await Episode.find(search) |
|||
.sort({ created: -1 }) |
|||
.skip(pagination.skip) |
|||
.limit(pagination.cpp) |
|||
.populate(this.populateEpisode) |
|||
.lean(); |
|||
|
|||
const totalEpisodeCount = await Episode.countDocuments(search); |
|||
return { episodes, totalEpisodeCount }; |
|||
} |
|||
|
|||
async getAll(pagination: WebPaginationParameters): Promise<EpisodeLibrary> { |
|||
const episodes = await Episode.find() |
|||
.sort({ created: -1 }) |
|||
.skip(pagination.skip) |
|||
.limit(pagination.cpp) |
|||
.populate(this.populateEpisode) |
|||
.lean(); |
|||
|
|||
const totalEpisodeCount = await Episode.estimatedDocumentCount(); |
|||
return { episodes, totalEpisodeCount }; |
|||
} |
|||
} |
|||
|
|||
export default EpisodeService; |
Loading…
Reference in new issue