Skip to content

Commit

Permalink
import fixes (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: John Livee Oroncillo <[email protected]>
  • Loading branch information
johnliveeoroncillo and johnlivee-singlifeph authored Apr 19, 2024
1 parent f0e8d42 commit f2d8f26
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 299 deletions.
21 changes: 6 additions & 15 deletions code_templates/ModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const numbers = [
const booleans = ['bool', 'boolean'];

const content = `import { Entity, Column } from 'typeorm';
import { Model } from '../../core/libs/Model';
import { Model } from '../../../core/libs/Model';
@Entity({
name: 'table_name',
})
Expand All @@ -41,7 +41,7 @@ export class ModelTemplate {

constructor(name: string, table_name?: string, type?: string) {
this.table_name = table_name ?? 'table_name';
this.name = pascalCase(`${name.trim()}${type}Model`);
this.name = pascalCase(`${name.trim()}Model`);
this.filename = `${this.name}.ts`;
this.type = type ?? 'mysql';
}
Expand All @@ -53,7 +53,6 @@ export class ModelTemplate {
if (existsSync(`./src/models/${this.type}/${this.filename}`)) throw new Error('Model file already existed');

const columns: string[] = [];

if (this.type === 'mysql') {
const connection: Connection = await Mysql.getConnection();
//CHECK MIGRATION TABLE
Expand All @@ -71,15 +70,7 @@ export class ModelTemplate {
else if (booleans.includes(element.DATA_TYPE)) type = 'boolean';

const column = `
@Column({
type: "${element.DATA_TYPE == 'enum' ? 'varchar' : element.DATA_TYPE}"${
element.CHARACTER_MAXIMUM_LENGTH == null ||
element.DATA_TYPE == 'text' ||
element.DATA_TYPE == 'enum'
? ''
: `,\n length: ${element.CHARACTER_MAXIMUM_LENGTH}`
}
})
@Column()
${element.COLUMN_NAME}: ${type};
`;
columns.push(column);
Expand All @@ -90,9 +81,9 @@ ${element.COLUMN_NAME}: ${type};
connection.close();
}

if (this.type === 'mongo') {
content.replace(/Model/g, 'MongoModel');
}
// if (this.type === 'mongo') {
// content.replace(/Model/g, 'MongoModel');
// }

writeFileSync(
`./src/models/${this.type}/${this.filename}`,
Expand Down
13 changes: 8 additions & 5 deletions code_templates/RepositoryTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { writeFileSync, existsSync, mkdirSync } from 'fs';
import { pascalCase } from 'case-anything';

let content = `import { EntityRepository, Repository } from 'typeorm';
import { model_name } from '../models/model_name';
import { model_name } from '../../models/db_type/model_name';
@EntityRepository(model_name)
export class <repository_name> extends Repository<model_name> {
async getAll(): Promise<model_name[]> {
Expand All @@ -24,14 +24,17 @@ export class RepositoryTemplate {
}

generate(): void {
if (!existsSync(`./src/models/${this.type}`)) {
mkdirSync(`./src/models/${this.type}`);
if (!existsSync(`./src/repository/${this.type}`)) {
mkdirSync(`./src/repository/${this.type}`);
}
if (existsSync(`./src/repository/${this.type}/${this.filename}`))
throw new Error('Repository file already existed');

const rawName = this.filename.replace(/Repository/g, '').replace(/\.[^/.]+$/, '');
content = content.replace(/model_name/g, `${rawName}Model`);
writeFileSync(`./src/repository/${this.filename}`, content.replace(/<repository_name>/g, this.name));
content = content.replace(/model_name/g, `${rawName}Model`).replace(/db_type/g, this.type);
writeFileSync(
`./src/repository/${this.type}/${this.filename}`,
content.replace(/<repository_name>/g, this.name),
);
}
}
6 changes: 2 additions & 4 deletions core/libs/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ export class Database {
username: this.username,
password: this.password,
database: this.db,
synchronize: this.dialect === Dialect.mongodb,
synchronize: false,
logging: this.logging,
entities: [
`${__dirname}/../../src/models/*${this.dialect === Dialect.mongodb ? 'MongoModel' : ''}.{ts,js}`,
],
entities: [`${__dirname}/../../src/models/*.{ts,js}`],
};

active[conn] = await createConnection(connectionOptions);
Expand Down
8 changes: 4 additions & 4 deletions core/libs/Email.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nodemailer, { TransportOptions } from 'nodemailer';
import nodemailer, { TransportOptions, Transporter } from 'nodemailer';
import { env } from './Env';
export interface EmailData {
from: string;
Expand All @@ -14,10 +14,10 @@ export class Email {
private SMTP_SECURE = Boolean(env('SMTP_SECURE', 'false'));
private SMTP_USERNAME: string = env('SMTP_USERNAME', '');
private SMTP_PASSWORD: string = env('SMTP_PASSWORD', '');
private transporter: any;
public mailer: Transporter;

constructor() {
this.transporter = nodemailer.createTransport({
this.mailer = nodemailer.createTransport({
host: this.SMTP_HOST,
port: this.SMTP_PORT,
secure: this.SMTP_SECURE,
Expand All @@ -29,6 +29,6 @@ export class Email {
}

async send(data: EmailData): Promise<void> {
return await this.transporter.sendMail(data);
return await this.mailer.sendMail(data);
}
}
1 change: 1 addition & 0 deletions core/libs/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Model extends BaseEntity {
@Generated('uuid')
public readonly uuid!: string;

@ObjectIdColumn()
@PrimaryGeneratedColumn()
public readonly id!: number | string | ObjectID;

Expand Down
2 changes: 1 addition & 1 deletion core/libs/MongoBaseRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeepPartial, ObjectLiteral, Repository, SaveOptions } from 'typeorm';
import { Carbon } from '../../core/libs/Carbon';
import { Carbon } from './Carbon';
import { v4 } from 'uuid';
export class MongoBaseRepository<T extends ObjectLiteral> extends Repository<T> {
async insertCollection(payload: ObjectLiteral): Promise<T> {
Expand Down
2 changes: 1 addition & 1 deletion core/libs/TokenService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import jwt from 'jsonwebtoken';
import { CustomResponse, Response401 } from '../defaults';
import { HttpRequest, Identity } from '../libs/ApiEvent';
import { HttpRequest, Identity } from './ApiEvent';
import { env } from './Env';

const JWT_TOKEN = env('JWT_TOKEN', '');
Expand Down
97 changes: 0 additions & 97 deletions src/functions/apis/db_healthcheck/action.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/functions/apis/db_healthcheck/config.yml

This file was deleted.

26 changes: 0 additions & 26 deletions src/functions/apis/db_healthcheck/handler.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/functions/apis/db_healthcheck/handler_test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/functions/apis/db_healthcheck/response.ts

This file was deleted.

Loading

0 comments on commit f2d8f26

Please sign in to comment.