Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#806-adding-OKR-module-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
abinandh15 committed Jun 10, 2020
2 parents 56afa4a + aa5bc57 commit 9b50517
Show file tree
Hide file tree
Showing 30 changed files with 984 additions and 49 deletions.
6 changes: 6 additions & 0 deletions apps/api/src/app/app.module.ts
Expand Up @@ -81,6 +81,7 @@ import { LanguagesEnum } from '@gauzy/models';
import { EventTypeModule } from './event-types/event-type.module';
import { AvailabilitySlotsModule } from './availability-slots/availability-slots.module';
import { HelpCenterModule } from './help-center/help-center.module';
import { PaymentModule } from './payment/payment.module';
import { CandidatePersonalQualitiesModule } from './candidate-personal-qualities/candidate-personal-qualities.module';

@Module({
Expand Down Expand Up @@ -318,6 +319,10 @@ import { CandidatePersonalQualitiesModule } from './candidate-personal-qualities
{
path: '/availability-slots',
module: AvailabilitySlotsModule
},
{
path: '/payments',
module: PaymentModule
}
]
}
Expand Down Expand Up @@ -371,6 +376,7 @@ import { CandidatePersonalQualitiesModule } from './candidate-personal-qualities
SkillModule,
InvoiceModule,
InvoiceItemModule,
PaymentModule,
EmployeeLevelModule,
EventTypeModule,
AvailabilitySlotsModule,
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/app/core/core.module.ts
Expand Up @@ -82,6 +82,7 @@ import { AvailabilitySlots } from '../availability-slots/availability-slots.enti
import { ProductTypeTranslation } from '../product-type/product-type-translation.entity';
import { HelpCenter } from '../help-center/help-center.entity';
import { ProductCategoryTranslation } from '../product-category/product-category-translation.entity';
import { Payment } from '../payment/payment.entity';
import { CandidatePersonalQualities } from '../candidate-personal-qualities/candidate-personal-qualities.entity';

const entities = [
Expand Down Expand Up @@ -159,7 +160,8 @@ const entities = [
EventType,
AvailabilitySlots,
ProductTypeTranslation,
ProductCategoryTranslation
ProductCategoryTranslation,
Payment
];

@Module({
Expand Down
12 changes: 10 additions & 2 deletions apps/api/src/app/invoice/invoice.entity.ts
Expand Up @@ -28,6 +28,7 @@ import { Organization } from '../organization/organization.entity';
import { OrganizationClients } from '../organization-clients/organization-clients.entity';
import { InvoiceItem } from '../invoice-item/invoice-item.entity';
import { Tag } from '../tags/tag.entity';
import { Payment } from '../payment/payment.entity';

@Entity('invoice')
@Unique(['invoiceNumber'])
Expand All @@ -37,7 +38,7 @@ export class Invoice extends Base implements IInvoice {
@JoinTable({
name: 'tag_invoice'
})
tags: Tag[];
tags?: Tag[];

@ApiProperty({ type: Date })
@IsDate()
Expand Down Expand Up @@ -89,7 +90,7 @@ export class Invoice extends Base implements IInvoice {
@ApiProperty({ type: Boolean })
@IsBoolean()
@Column({ nullable: true })
emailSent: boolean;
emailSent?: boolean;

@ApiProperty({ type: Boolean })
@IsBoolean()
Expand Down Expand Up @@ -146,4 +147,11 @@ export class Invoice extends Base implements IInvoice {
})
@JoinColumn()
invoiceItems?: InvoiceItem[];

@ApiPropertyOptional({ type: Payment, isArray: true })
@OneToMany((type) => Payment, (payment) => payment.invoice, {
onDelete: 'SET NULL'
})
@JoinColumn()
payments?: InvoiceItem[];
}
76 changes: 76 additions & 0 deletions apps/api/src/app/payment/payment.controller.ts
@@ -0,0 +1,76 @@
import { CrudController, IPagination } from '../core';
import { ApiTags } from '@nestjs/swagger';
import {
Controller,
UseGuards,
Query,
Get,
HttpCode,
HttpStatus,
Put,
Param,
Body,
Post,
Delete
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Payment } from './payment.entity';
import { PaymentService } from './payment.service';
import { Payment as IPayment, PermissionsEnum } from '@gauzy/models';
import { ParseJsonPipe } from '../shared';
import { PermissionGuard } from '../shared/guards/auth/permission.guard';
import { Permissions } from '../shared/decorators/permissions';

@ApiTags('Payment')
@UseGuards(AuthGuard('jwt'))
@Controller()
export class PaymentController extends CrudController<Payment> {
constructor(private paymentService: PaymentService) {
super(paymentService);
}

@HttpCode(HttpStatus.ACCEPTED)
@UseGuards(PermissionGuard)
@Permissions(PermissionsEnum.INVOICES_EDIT)
@Get()
async findAllInvoices(
@Query('data', ParseJsonPipe) data: any
): Promise<IPagination<IPayment>> {
const { relations = [], findInput = null } = data;

return this.paymentService.findAll({
where: findInput,
relations
});
}

@HttpCode(HttpStatus.ACCEPTED)
@UseGuards(PermissionGuard)
@Permissions(PermissionsEnum.INVOICES_EDIT)
@Post()
async createPayment(@Body() entity: IPayment): Promise<any> {
return this.paymentService.create(entity);
}

@HttpCode(HttpStatus.ACCEPTED)
@UseGuards(PermissionGuard)
@Permissions(PermissionsEnum.INVOICES_EDIT)
@Put(':id')
async updatePayment(
@Param('id') id: string,
@Body() entity: IPayment
): Promise<any> {
return this.paymentService.create({
id,
...entity
});
}

@HttpCode(HttpStatus.ACCEPTED)
@UseGuards(PermissionGuard)
@Permissions(PermissionsEnum.INVOICES_EDIT)
@Delete(':id')
async deleteTask(@Param('id') id: string): Promise<any> {
return this.paymentService.delete(id);
}
}
94 changes: 94 additions & 0 deletions apps/api/src/app/payment/payment.entity.ts
@@ -0,0 +1,94 @@
import {
Entity,
Column,
ManyToOne,
JoinColumn,
RelationId,
JoinTable,
ManyToMany
} from 'typeorm';
import { Base } from '../core/entities/base';
import { Payment as IPayment, CurrenciesEnum } from '@gauzy/models';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
IsEnum,
IsString,
IsOptional,
IsDate,
IsNumber
} from 'class-validator';
import { Tenant } from '../tenant/tenant.entity';
import { Tag } from '../tags/tag.entity';
import { User } from '../user/user.entity';
import { Invoice } from '../invoice/invoice.entity';

@Entity('payment')
export class Payment extends Base implements IPayment {
@ApiPropertyOptional({ type: String })
@IsString()
@IsOptional()
@Column({ nullable: true })
invoiceId?: string;

@ApiPropertyOptional({ type: Invoice })
@ManyToOne((type) => Invoice, (invoice) => invoice.payments, {
onDelete: 'SET NULL'
})
@JoinColumn()
invoice?: Invoice;

@ApiPropertyOptional({ type: String })
@IsString()
@IsOptional()
@Column({ nullable: true })
organizationId?: string;

@ApiPropertyOptional({ type: String })
@IsString()
@IsOptional()
@Column({ nullable: true })
userId?: string;

@ApiPropertyOptional({ type: User })
@ManyToOne((type) => User)
@JoinColumn()
recordedBy?: User;

@ApiPropertyOptional({ type: Date })
@IsDate()
@IsOptional()
@Column({ nullable: true })
paymentDate?: Date;

@ApiPropertyOptional({ type: Number })
@IsNumber()
@IsOptional()
@Column({ nullable: true, type: 'numeric' })
amount?: number;

@ApiPropertyOptional({ type: String })
@IsString()
@IsOptional()
@Column()
note?: string;

@ApiPropertyOptional({ type: String, enum: CurrenciesEnum })
@IsEnum(CurrenciesEnum)
@Column()
currency?: string;

@ApiProperty({ type: Tenant })
@ManyToOne(() => Tenant, { nullable: true, onDelete: 'CASCADE' })
@JoinColumn()
tenant?: Tenant;

@ApiProperty({ type: String, readOnly: true })
@RelationId((payment: Payment) => payment.tenant)
readonly tenantId?: string;

@ManyToMany(() => Tag)
@JoinTable({
name: 'tag_payment'
})
tags?: Tag[];
}
15 changes: 15 additions & 0 deletions apps/api/src/app/payment/payment.module.ts
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Payment } from './payment.entity';
import { PaymentController } from './payment.controller';
import { PaymentService } from './payment.service';
import { UserService } from '../user/user.service';
import { User } from '../user/user.entity';

@Module({
imports: [TypeOrmModule.forFeature([User, Payment])],
controllers: [PaymentController],
providers: [PaymentService, UserService],
exports: [PaymentService, UserService]
})
export class PaymentModule {}
15 changes: 15 additions & 0 deletions apps/api/src/app/payment/payment.service.ts
@@ -0,0 +1,15 @@
import { CrudService } from '../core';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Injectable } from '@nestjs/common';
import { Payment } from './payment.entity';

@Injectable()
export class PaymentService extends CrudService<Payment> {
constructor(
@InjectRepository(Payment)
private readonly paymentRepository: Repository<Payment>
) {
super(paymentRepository);
}
}
15 changes: 14 additions & 1 deletion apps/api/src/app/user/user.entity.ts
Expand Up @@ -24,13 +24,15 @@ import {
ManyToMany,
JoinTable,
OneToOne,
AfterLoad
AfterLoad,
OneToMany
} from 'typeorm';
import { Base } from '../core/entities/base';
import { Role } from '../role/role.entity';
import { Tenant } from '../tenant/tenant.entity';
import { Tag } from '../tags/tag.entity';
import { Employee } from '../employee/employee.entity';
import { Payment } from '../payment/payment.entity';

@Entity('user')
export class User extends Base implements IUser {
Expand Down Expand Up @@ -111,6 +113,17 @@ export class User extends Base implements IUser {
@Column({ length: 500, nullable: true })
imageUrl?: string;

@ApiPropertyOptional({ type: Payment, isArray: true })
@OneToMany((type) => Payment, (payments) => payments.recordedBy)
@JoinColumn()
payments?: Payment[];

@ApiPropertyOptional({ type: String })
@IsString()
@IsOptional()
@Column({ nullable: true })
paymentsId?: string;

@ApiProperty({ type: String, enum: LanguagesEnum })
@IsEnum(LanguagesEnum)
@Column({ nullable: true })
Expand Down
43 changes: 43 additions & 0 deletions apps/gauzy/src/app/@core/services/payment.service.ts
@@ -0,0 +1,43 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Payment, PaymentFindInput, PaymentUpdateInput } from '@gauzy/models';
import { first } from 'rxjs/operators';

@Injectable()
export class PaymentService {
constructor(private http: HttpClient) {}

getAll(
relations?: string[],
findInput?: PaymentFindInput
): Promise<{ items: Payment[] }> {
const data = JSON.stringify({ relations, findInput });
return this.http
.get<{ items: Payment[] }>('/api/payments', {
params: { data }
})
.pipe(first())
.toPromise();
}

add(payment: Payment): Promise<Payment> {
return this.http
.post<Payment>('/api/payments', payment)
.pipe(first())
.toPromise();
}

update(id: string, updateInput: PaymentUpdateInput): Promise<Payment> {
return this.http
.put<Payment>(`/api/payments/${id}`, updateInput)
.pipe(first())
.toPromise();
}

delete(id: string): Promise<any> {
return this.http
.delete(`/api/payments/${id}`)
.pipe(first())
.toPromise();
}
}
Expand Up @@ -279,7 +279,7 @@ <h3 *ngIf="isEstimate">
</div>
</div>
</div>
<div class="row">
<!-- <div class="row">
<div class="col-sm-12">
<div class="form-group">
<nb-checkbox formControlName="paid">
Expand All @@ -289,7 +289,7 @@ <h3 *ngIf="isEstimate">
</nb-checkbox>
</div>
</div>
</div>
</div> -->
<div class="row">
<div class="col-sm-3">
<div class="form-group">
Expand Down

0 comments on commit 9b50517

Please sign in to comment.