-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] Create video plugin module (#8613)
* feat: adds video model and refactors imports Introduces a new video model to support video functionalities. This includes properties for video metadata, storage information, and relationships with other models like time slots and employees. Additionally, several imports are reorganized for better code structure. * feat: adds Video entity This introduces the `Video` entity to store video-related information, including title, file path, recording date, duration, size, URL, storage provider, description, resolution, codec, frame rate, and uploader details. It includes validation and relationships with `TimeSlot` and `Employee` entities. * feat: introduces file storage path generation This change introduces a new mechanism for generating file storage paths. It uses a combination of date, tenant ID, and employee ID to create unique and organized storage locations. A factory class simplifies the creation of storage engines with this path generation logic. * feat(videos): adds DTOs for video management Introduces Data Transfer Objects (DTOs) for creating, updating, and deleting videos. Includes a FileDTO for handling video uploads and a BaseVideoDTO for common video properties. These DTOs provide type safety and validation for video-related operations. * feat: adds video repositories for MikroORM and TypeORM Introduces `MikroOrmVideoRepository` and `TypeOrmVideoRepository` to support different ORM integrations. * feat: adds video service Introduces a new service to manage video entities. It utilizes both TypeORM and MikroORM repositories for data access. * feat: add video entity and migration This commit introduces the `Video` entity and its corresponding database migration. The migration creates the `videos` table with fields for video metadata like title, file path, duration, size, storage provider, and relations to other entities such as tenant, organization, time slot, and uploading employee. It also includes indexes for efficient querying. The migration handles different database types (PostgreSQL, SQLite, Better SQLite3, MySQL) and includes specific up and down migration logic for each. * feat: adds commands and handlers for video management This commit introduces new commands and handlers for managing videos: - Creates `CreateVideoCommand` and `CreateVideoHandler` to add new videos. - Implements `UpdateVideoCommand` and `UpdateVideoHandler` to modify existing videos. - Adds `DeleteVideoCommand` and `DeleteVideoHandler` to remove videos. This change enables basic CRUD operations for videos within the application. * feat: adds queries and handlers for fetching videos This introduces new queries and handlers for retrieving video data: - `GetVideoQuery` and `GetVideoQueryHandler`: Fetch a single video by ID. - `GetVideosQuery` and `GetVideosQueryHandler`: Fetch a list of videos with pagination support. * feat: adds video subscriber for lifecycle management Implements a TypeORM subscriber for the `Video` entity to manage file storage during entity lifecycle events. - Sets the `fullUrl` property after loading a video entity by retrieving the URL from the configured storage provider. - Deletes the associated video file from storage after a video entity is deleted. This ensures consistent data and efficient storage management by automatically handling file operations related to videos. * feat(videos): implements video controller This commit introduces a new video controller feature, including: - Creating new video records with associated metadata and file uploads. - Retrieving video records by ID. - Listing all video records with pagination support. - Deleting video records. The implementation uses CQRS and leverages a file storage service for managing video files. It also includes validation and error handling for file uploads and data integrity. * feat: Implements video plugin module This commit introduces a new video plugin. It includes: - A new module for videos with controllers, services, and repositories. - Integration with TypeORM and MikroORM for database operations. - CQRS implementation for handling commands and queries. - Role-based permission management. - Routing configuration for the plugin. * feat: adds video entity and subscriber Introduces the `Video` entity and its corresponding subscriber to the core module. This lays the foundation for managing video data within the application. * feat: adds PluginModule to AppModule Registers the PluginModule in the application's root module to enable plugin functionality. * fix: cspell spelling * feat(plugin-video-capture): create library for video capture plugin * refactor: plugin video capture module & entity * fix(migration): video table for plugin video capture * fix(videos): Implement query handlers for video CRUD operations * fix(migration): refactor `video` [table] for MySQL * refactor: suggestion by coderabbit AI * fix(migration): refactor `video` [table] for DBs * fix(subscriber): video subscriber initialization and event handling * fix(cspell): typo spelling :-) --------- Co-authored-by: Rahul R. <rahulrathore576@gmail.com>
- Loading branch information
1 parent
c0187af
commit cfc5015
Showing
60 changed files
with
1,693 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/core/src/lib/core/file-storage/helpers/directory-path-generator.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface IDirectoryPathGenerator { | ||
getBaseDirectory(name: string): string; | ||
getSubDirectory(): string; | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/core/src/lib/core/file-storage/helpers/directory-path-generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Concrete implementation of the path generator | ||
import * as moment from 'moment'; | ||
import * as path from 'path'; | ||
import { v4 as uuid } from 'uuid'; | ||
import { RequestContext } from '../../context'; | ||
import { IDirectoryPathGenerator } from './directory-path-generator.interface'; | ||
|
||
export class DirectoryPathGenerator implements IDirectoryPathGenerator { | ||
/** | ||
* Generates the base directory path with the given name. | ||
* Includes a timestamped subdirectory in the format `YYYY/MM/DD`. | ||
* | ||
* @param name - The name to be used as the base directory. | ||
* @returns The full base directory path including the timestamped subdirectory. | ||
*/ | ||
public getBaseDirectory(name: string): string { | ||
return path.join(name, moment().format('YYYY/MM/DD')); | ||
} | ||
|
||
/** | ||
* Generates a subdirectory path specific to the current user context. | ||
* Uses the `tenantId` and `employeeId` from the current user, or generates UUIDs if not available. | ||
* | ||
* @returns The subdirectory path in the format `<tenantId>/<employeeId>`. | ||
*/ | ||
public getSubDirectory(): string { | ||
// Retrieve the current user from the request context | ||
const user = RequestContext.currentUser(); | ||
|
||
// Extract or generate identifiers for the tenant and employee | ||
const tenantId = user?.tenantId || uuid(); // Use the tenantId if available, otherwise generate a UUID | ||
const employeeId = user?.employeeId || uuid(); // Use the employeeId if available, otherwise generate a UUID | ||
|
||
// Construct and return the subdirectory path | ||
return path.join(tenantId, employeeId); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/core/src/lib/core/file-storage/helpers/file-storage-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import multer from 'multer'; | ||
import * as path from 'path'; | ||
import { FileStorage } from '../file-storage'; | ||
import { DirectoryPathGenerator } from './directory-path-generator'; | ||
import { IDirectoryPathGenerator } from './directory-path-generator.interface'; | ||
|
||
// FileStorageFactory | ||
export class FileStorageFactory { | ||
private static readonly pathGenerator: IDirectoryPathGenerator = new DirectoryPathGenerator(); | ||
|
||
public static create(baseDirname: string): multer.StorageEngine { | ||
const baseDirectory = this.pathGenerator.getBaseDirectory(baseDirname); | ||
const subDirectory = this.pathGenerator.getSubDirectory(); | ||
|
||
return new FileStorage().storage({ | ||
dest: () => path.join(baseDirectory, subDirectory), | ||
prefix: baseDirname | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './directory-path-generator'; | ||
export * from './directory-path-generator.interface'; | ||
export * from './file-storage-factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './file-storage'; | ||
export * from './file-storage.module'; | ||
export * from './helpers'; | ||
export * from './tenant-settings.middleware'; | ||
export * from './uploaded-file-storage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './cloud-migrate.interceptor'; | ||
export * from './serializer.interceptor'; | ||
export * from './lazy-file-interceptor'; | ||
export * from './transform.interceptor'; | ||
export * from './transform.interceptor'; |
Oops, something went wrong.