Skip to content

Commit

Permalink
Merge pull request #89 from DigiChanges/feat/NR/add-public-bucket
Browse files Browse the repository at this point in the history
feat: add public bucket and delete endpoint
  • Loading branch information
Murzbul authored Feb 28, 2022
2 parents b1e809f + c09fac8 commit fb4c8ef
Show file tree
Hide file tree
Showing 103 changed files with 2,502 additions and 2,321 deletions.
7 changes: 4 additions & 3 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ MINIO_ACCESS_KEY=minio
MINIO_SECRET_KEY=12345678
MINIO_USE_SSL=false
MINIO_PORT=9000
MINIO_BUCKET_NAME=experience
MINIO_PUBLIC_BUCKET=experience.private
MINIO_PRIVATE_BUCKET=experience.public
MINIO_REGION=us-east-1
FILLESYSTEM_DEFAULT=minio
FILESYSTEM_DEFAULT=minio

TZ=UTC

Expand All @@ -42,7 +43,7 @@ SMTP_PORT=1025
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_SECURE_SSL=false
SMTP_SENDERNAME=Notifications
SMTP_SENDER_NAME=Notifications
SMTP_SENDER_EMAIL_DEFAULT=[email protected]

URL_API=http://localhost:8089/api/
Expand Down
17 changes: 9 additions & 8 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ CACHE_HOST=redis
CACHE_PORT=6379
CACHE_PASSWORD=ewsua132435

minio_HOST=minio
minio_ACCESS_KEY=minio
minio_SECRET_KEY=12345678
minio_USE_SSL=false
minio_PORT=9000
MINIO_HOST=minio
MINIO_ACCESS_KEY=minio
MINIO_SECRET_KEY=12345678
MINIO_USE_SSL=false
MINIO_PORT=9000
MINIO_REGION=us-east-1
S3_BUCKET_NAME=experience
FILLESYSTEM_DEFAULT=minio
MINIO_PUBLIC_BUCKET=experience.public
MINIO_PRIVATE_BUCKET=experience.private
FILESYSTEM_DEFAULT=minio

TZ=UTC

Expand All @@ -40,7 +41,7 @@ SMTP_PORT=25
SMTP_USERNAME=yourusername
SMTP_PASSWORD=yourpassword
SMTP_SECURE_SSL=false
SMTP_SENDERNAME=Notifications
SMTP_SENDER_NAME=Notifications
SMTP_SENDER_EMAIL_DEFAULT=[email protected]

URL_API=http://localhost:80/api/
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/require-await': 0,
"@typescript-eslint/type-annotation-spacing": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-argument": 0,
'no-mixed-spaces-and-tabs': 0
}
};
5 changes: 3 additions & 2 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"useSSL": "MINIO_USE_SSL",
"port": "MINIO_PORT",
"region": "MINIO_REGION",
"bucket": "MINIO_BUCKET_NAME"
"publicBucket": "MINIO_PUBLIC_BUCKET",
"privateBucket": "MINIO_PRIVATE_BUCKET"
},
"local": "",
"default": "FILESYSTEM_DEFAULT"
Expand All @@ -63,7 +64,7 @@
"port": "SMTP_PORT",
"username": "SMTP_USERNAME",
"password": "SMTP_PASSWORD",
"senderName": "SMTP_SENDERNAME",
"senderName": "SMTP_SENDER_NAME",
"senderEmailDefault": "SMTP_SENDER_EMAIL_DEFAULT"
},
"push": {
Expand Down
3 changes: 2 additions & 1 deletion config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"useSSL": false,
"port": 9000,
"region": "us-east-1",
"bucket": "experience"
"publicBucket": "experience",
"privateBucket": "experience"
},
"local": {
"type": "local"
Expand Down
3 changes: 2 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"useSSL": false,
"port": 9000,
"region": "us-east-1",
"bucket": "experience"
"publicBucket": "experience",
"privateBucket": "experience"
},
"local": {
"type": "local"
Expand Down
3 changes: 2 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"useSSL": false,
"port": 9000,
"region": "us-east-1",
"bucket": "experience"
"publicBucket": "experience.public",
"privateBucket": "experience.private"
},
"local": {
"type": "local"
Expand Down
2 changes: 1 addition & 1 deletion dev.init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ yarn command addUserRole --role SuperAdmin --email [email protected] --firstNa
yarn command activeUser --email [email protected]
yarn command activeUser --email [email protected]
yarn command syncRolesPermission
yarn command createBucket --bucketName experience --region us-east-1
yarn command createBucket --name experience --region us-east-1
4 changes: 2 additions & 2 deletions docs/coming_soon.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Bash dev.init.sh Content
npx ts-node src/command.ts addUserRole --role Admin --email [email protected] --firstName node --lastName node --password 12345678 --documentType DNI --documentNumber 12345678 --gender male --phone 541112345678 --country AR --address av.1234 --isSuperAdmin false --birthday 04/07/1990
npx ts-node src/command.ts addUserRole --role SuperAdmin --email [email protected] --firstName super --lastName admin --documentType DNI --documentNumber 12345679 --gender male --phone 541112345678 --country AR --address av.1234 --password 12345678 --birthday 05/07/1990 --isSuperAdmin true
npx ts-node src/command.ts syncRolesPermission
npx ts-node src/command.ts createBucket --bucketName experience --region us-east-1
npx ts-node src/command.ts createBucket --name experience --region us-east-1
```

Create Push Notifications Keys
Expand Down Expand Up @@ -122,5 +122,5 @@ To change from Mongoose to TypeORM the following steps must be followed:
* ```npx ts-node src/command.ts addUserRole --role Admin --email [email protected] --firstName node --lastName node --password 12345678 --isSuperAdmin false```
* ```npx ts-node src/command.ts addUserRole --role SuperAdmin --email [email protected] --firstName super --lastName admin --password 12345678 --isSuperAdmin true```
* ```npx ts-node src/command.ts syncRolesPermission```
* ```npx ts-node src/command.ts createBucket --bucketName experience --region us-east-1```
* ```npx ts-node src/command.ts createBucket --name experience --region us-east-1```
* ```npx ts-node src/command.ts createVapID```
2 changes: 1 addition & 1 deletion docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Remember to generate the .env file for the system environment variables. You can
yarn command addUserRole --role Admin --email [email protected] --firstName node --lastName node --password 12345678 --documentType DNI --documentNumber 12345678 --gender male --phone 541112345678 --country AR --address av.1234 --isSuperAdmin false --birthday 04/07/1990
yarn command addUserRole --role SuperAdmin --email [email protected] --firstName super --lastName admin --documentType DNI --documentNumber 12345679 --gender male --phone 541112345678 --country AR --address av.1234 --password 12345678 --birthday 05/07/1990 --isSuperAdmin true
yarn command syncRolesPermission
yarn command createBucket --bucketName experience --region us-east-1
yarn command createBucket --name experience --region us-east-1
```

## Create Push Notifications Keys
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test-watch": "npx jest --watch --silent --coverage=false",
"watch": "nodemon dist/src/index.js",
"prepare": "husky install",
"sincronize": "npx ts-node src/App/Presentation/Commands/sincronizeMikroORM.ts"
"sync-db": "npx ts-node src/App/Presentation/Commands/SynchronizeMikroORM.ts"
},
"nodemonConfig": {
"execMap": {
Expand Down Expand Up @@ -166,7 +166,7 @@
"lint-staged": "^11.2.6",
"nodemon": "^2.0.7",
"npm-run-all": "^4.1.5",
"parcel": "^2.3.1",
"parcel": "^2.3.2",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"supertest": "^6.1.3",
Expand Down
4 changes: 2 additions & 2 deletions src/App/Infrastructure/Repositories/BaseSqlRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class BaseSqlRepository<T> implements IBaseRepository<T>

async save(entity: T): Promise<T>
{
return await this.repository.save(entity);
return await this.repository.save(entity as any);
}

async getOne(id: string): Promise<T>
Expand All @@ -35,7 +35,7 @@ abstract class BaseSqlRepository<T> implements IBaseRepository<T>

async update(entity: T): Promise<T>
{
return await this.repository.save(entity);
return await this.repository.save(entity as any);
}

async delete(id: string): Promise<T>
Expand Down
2 changes: 1 addition & 1 deletion src/App/Presentation/Requests/IdRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IdRequest implements IdPayload
@decorate(IsUUID('4'))
id: string;

constructor(id: string)
constructor({ id }: { id: string })
{
this.id = id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/Presentation/Shared/Express/Responder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Transformer
} from '@digichanges/shared-experience';
import { TYPES } from '../../../../Config/Injects/types';
import IFileDTO from '../../../../File/InterfaceAdapters/Payloads/IFileDTO';
import IFileDTO from '../../../../File/Domain/Payloads/IFileDTO';
import IFormatResponder from '../../../../Shared/InterfaceAdapters/IFormatResponder';

@injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/App/Presentation/Shared/Koa/Responder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Koa from 'koa';
import { IHttpStatusCode, IPaginator, PaginatorTransformer, Transformer } from '@digichanges/shared-experience';

import IFormatResponder from '../../../../Shared/InterfaceAdapters/IFormatResponder';
import IFileDTO from '../../../../File/InterfaceAdapters/Payloads/IFileDTO';
import IFileDTO from '../../../../File/Domain/Payloads/IFileDTO';
import FormatResponder from '../FormatResponder';
import FormatError from '../FormatError';
import ErrorHttpException from '../ErrorHttpException';
Expand Down
7 changes: 7 additions & 0 deletions src/App/Presentation/Transformers/BaseTransformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export type BasePropertiesTransformer = { id: string, createdAt: number, updatedAt: number };
type OmitPropertiesTransformer = 'createdAt' | 'updatedAt';

type BaseTransformer<T> = Partial<Omit<T, OmitPropertiesTransformer>>;

export default BaseTransformer;
6 changes: 3 additions & 3 deletions src/Auth/Domain/UseCases/LoginUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ class LoginUseCase
const password = payload.getPassword();
const user = await this.repository.getOneByEmail(email);

if (user.verify === false)
if (!user.verify)
{
throw new UnverifiedUserException();
}

if (user.enable === false)
if (!user.enable)
{
throw new UserDisabledException();
}

const roleDisabled = user.getRoles().find(role => role.enable === false);
const roleDisabled = user.getRoles().find(role => !role.enable);

if (roleDisabled)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Config/mainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ type RedisConfig = {
password: string;
};

type MinioConfig = {
export type MinioConfig = {
endPoint: string;
accessKey: string;
secretKey: string;
useSSL: boolean;
port: number;
region: string;
bucket: string;
publicBucket: string;
privateBucket: string;
};

type JwtConfig = {
Expand Down
18 changes: 17 additions & 1 deletion src/Config/validateEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,41 @@ export function validateEnv()
return cleanEnv(process.env, {
NODE_ENV: str(),
SERVER_PORT: port(),

DB_HOST: str(),
DB_USER: str(),
DB_DATABASE: str(),
DB_PASSWORD: str(),
DB_PORT: port(),
DB_SYNCHRONIZE: bool(),
DB_TYPE_DEFAULT: str(),

MINIO_HOST: str(),
MINIO_ACCESS_KEY: str(),
MINIO_SECRET_KEY: str(),
MINIO_USE_SSL: bool(),
MINIO_PORT: port(),
MINIO_BUCKET_NAME_PUBLIC: str(),
MINIO_BUCKET_NAME_PRIVATE: str(),
MINIO_REGION: str(),
FILESYSTEM_DEFAULT: str(),

TZ: str(),

JWT_SECRET: str(),
JWT_EXPIRES: num(),
JWT_ISS: str(),
JWT_AUD: str(),

SMTP_HOST: str(),
SMTP_PORT: num(),
SMTP_SECURE_SSL: bool(),
SMTP_SENDERNAME: str(),
SMTP_SENDER_NAME: str(),
SMTP_SENDER_EMAIL_DEFAULT: str(),

URL_API: url(),
URL_WEB: url(),

AUTHORIZATION: bool(),
PRODUCT_NAME: str(),
ENCRYPTION_DEFAULT: str(),
Expand Down
23 changes: 20 additions & 3 deletions src/File/Domain/Entities/File.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IFileDomain from '../../InterfaceAdapters/IFileDomain';
import IFileDomain from './IFileDomain';
import Base from '../../../App/Domain/Entities/Base';

class File extends Base implements IFileDomain
Expand All @@ -10,12 +10,29 @@ class File extends Base implements IFileDomain
extension: string;
size: number;
version: number;
isPublic: boolean;

constructor()
constructor({ originalName = 'empty.jpg', hasOriginalName = false })
{
super();
this.name = this._id;
this.version = 1;
this.isPublic = false;
this.originalName = originalName;
this.setName(hasOriginalName);
}

private setName(hasOriginalName: boolean)
{
this.name = this._id;

if (hasOriginalName)
{
this.name = this.originalName
.toLowerCase()
.replace(/^\s+|\s+$/gm, '')
.replace(/\s+/g, ' ')
.replace(/ /g, '_');
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IBaseDomain from '../../App/InterfaceAdapters/IBaseDomain';
import IBaseDomain from '../../../App/InterfaceAdapters/IBaseDomain';

interface IFileDomain extends IBaseDomain
{
Expand All @@ -9,6 +9,7 @@ interface IFileDomain extends IBaseDomain
extension: string;
size: number;
version: number;
isPublic: boolean;
}

export default IFileDomain;
File renamed without changes.
10 changes: 10 additions & 0 deletions src/File/Domain/Payloads/CreateBucketPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

interface CreateBucketPayload
{
getName(): string;
getRegion(): string;
getPublicBucketPolicy(): string;
getPrivateBucketPolicy(): string;
}

export default CreateBucketPayload;
9 changes: 9 additions & 0 deletions src/File/Domain/Payloads/FileBase64RepPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FileOptionsQueryPayload from './FileOptionsQueryPayload';
import FileRepPayload from './FileRepPayload';

interface FileBase64RepPayload extends FileRepPayload, FileOptionsQueryPayload
{
getBase64(): string,
}

export default FileBase64RepPayload;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import internal from 'stream';
import IFileDomain from '../IFileDomain';
import IFileDomain from '../Entities/IFileDomain';
import IFileDTO from './IFileDTO';

class FileDTO implements IFileDTO
Expand Down
9 changes: 9 additions & 0 deletions src/File/Domain/Payloads/FileMultipartRepPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FileOptionsQueryPayload from './FileOptionsQueryPayload';
import FileRepPayload from './FileRepPayload';

interface FileMultipartRepPayload extends FileRepPayload, FileOptionsQueryPayload
{
getFile(): any;
}

export default FileMultipartRepPayload;
9 changes: 9 additions & 0 deletions src/File/Domain/Payloads/FileOptionsQueryPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

interface FileOptionsQueryPayload
{
getIsOriginalName(): boolean;
getIsPublic(): boolean;
getIsOverwrite(): boolean;
}

export default FileOptionsQueryPayload;
Loading

0 comments on commit fb4c8ef

Please sign in to comment.