refactor: 重构项目支持TypeORM数据库持久化
新增数据库实体类与服务实现,将内存存储扩展为支持数据库的完整实现,包括: 1. 新增Drama和Episode实体类,添加多个业务字段 2. 重构DramasService实现数据库CRUD与业务逻辑 3. 升级相关服务类为异步方法适配数据库操作 4. 更新测试用例适配异步接口变更 5. 完善分页、数据转换等辅助工具方法
This commit is contained in:
@@ -22,8 +22,10 @@ export class OrdersService {
|
||||
|
||||
constructor(private readonly dramasService: DramasService) {}
|
||||
|
||||
createOrder(user: UserRecord, dto: CreateOrderDto): OrderRecord {
|
||||
const episode = this.dramasService.getPublishedEpisodeOrThrow(dto.episodeId);
|
||||
async createOrder(user: UserRecord, dto: CreateOrderDto): Promise<OrderRecord> {
|
||||
const episode = await this.dramasService.getPublishedEpisodeOrThrow(
|
||||
dto.episodeId,
|
||||
);
|
||||
if (!episode.isPaid) {
|
||||
throw new UnprocessableEntityException('Episode is free');
|
||||
}
|
||||
@@ -46,8 +48,8 @@ export class OrdersService {
|
||||
return order;
|
||||
}
|
||||
|
||||
getPlayback(user: UserRecord, episodeId: number) {
|
||||
const episode = this.dramasService.getPublishedEpisodeOrThrow(episodeId);
|
||||
async getPlayback(user: UserRecord, episodeId: number) {
|
||||
const episode = await this.dramasService.getPublishedEpisodeOrThrow(episodeId);
|
||||
const isUnlocked =
|
||||
!episode.isPaid ||
|
||||
this.unlocks.some(
|
||||
@@ -107,8 +109,8 @@ export class OrdersService {
|
||||
};
|
||||
}
|
||||
|
||||
hasEpisodePermission(userId: number, episodeId: number) {
|
||||
const episode = this.dramasService.getPublishedEpisodeOrThrow(episodeId);
|
||||
async hasEpisodePermission(userId: number, episodeId: number) {
|
||||
const episode = await this.dramasService.getPublishedEpisodeOrThrow(episodeId);
|
||||
return !episode.isPaid || this.isUnlocked(userId, episodeId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user