0.14.3 • Published 5 months ago

@peersyst/storage-module v0.14.3

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

Description

Nest framework TypeScript base storage module.

Installation

$ npm install --save @peersyst/storage-module

How to use it

Base storage module

  • Import and register StorageModule in AppModule
import { Module } from "@nestjs/common";
import { StorageModule, StorageType } from "@peersyst/storage-module";

@Module({
    imports: [
        ConfigModule.forRoot(...),
        StorageModule.register(ConfigModule, {
          storageType: StorageType.LOCAL,
        }),
        ...
    ],
    ...
})
export class AppModule {}
  • Add StorageErrorCode and StorageErrorBody to app ErrorCodes
import { HttpStatus } from "@nestjs/common";
import { StorageErrorCode, StorageErrorBody } from "@peersyst/storage-module";

// Define app error codes
enum AppErrorCode {}

export const ErrorCode = { ...AppErrorCode, ...StorageErrorCode };
export type ErrorCodeType = AppErrorCode | StorageErrorCode;

export const ErrorBody: { [code in ErrorCodeType]: { statusCode: HttpStatus; message: string } } = {
    // Define app error code bodies
    ...StorageErrorBody,
};
  • Import StorageModule in the modules you want to use it
import { Module } from "@nestjs/common";
import { StorageModule, StorageType } from "@peersyst/storage-module";

@Module({
    imports: [
        StorageModule.register(ConfigModule, {
          storageType: StorageType.LOCAL,
        }),
        ...
    ],
    ...
})
export class ResourceModule {}
  • Inject StorageService in the in the classes you want to use it
import { InjectRepository, Inject } from "@nestjs/common";
import { StorageServiceInterface } from "@peersyst/storage-module";

export class ResourceService {
  constructor(
    @InjectRepository(Resource) private readonly resourceRepository: Repository<Resource>,
    @Inject("StorageService") private readonly storageService: StorageServiceInterface,
  )
}

S3 Storage Type

  • Add configService configuration variables
export default (): any => ({
    aws: {
        region: process.env.AWS_REGION,
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        bucketName: process.env.AWS_BUCKET_NAME,
    },
});

Local Storage Type

  • Add configService configuration variables
export default (): any => ({
    local: {
        rootPath: process.env.LOCAL_ROOT_PATH,
    },
});

License

Nest is MIT licensed.

0.14.0

5 months ago

0.14.1

5 months ago

0.14.2

5 months ago

0.13.3

7 months ago

0.14.3

5 months ago

0.13.0

1 year ago

0.12.69

2 years ago

0.12.66

2 years ago

0.12.61

2 years ago

0.12.40

2 years ago

0.12.15

2 years ago

0.12.0

2 years ago

0.11.36

2 years ago

0.11.35

2 years ago

0.11.34

2 years ago

0.11.33

2 years ago

0.11.32

2 years ago

0.11.31

2 years ago

0.11.30

2 years ago

0.11.29

2 years ago

0.11.28

2 years ago

0.11.21

2 years ago

0.11.20

2 years ago

0.11.19

2 years ago

0.11.13

2 years ago

0.11.12

2 years ago

0.11.11

2 years ago

0.11.10

2 years ago

0.11.9

2 years ago

0.11.8

2 years ago

0.11.7

2 years ago

0.11.6

2 years ago

0.11.5

2 years ago

0.11.4

2 years ago

0.11.3

2 years ago

0.11.2

2 years ago

0.11.1

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago