Skip to content

Commit

Permalink
Tax resolver (#168)
Browse files Browse the repository at this point in the history
* tax resolver added

* displayName is a field

* correctly build and push the current commit

* fix where for documentnumbersequence

* formatted

* add optimize imports

* imports organized

* prettier in the client

* fix the sales invoice duplication

* formatted

---------

Co-authored-by: David Podhola <[email protected]>
  • Loading branch information
davidpodhola and podholadavid authored Jul 12, 2024
1 parent dd70b5d commit 18386d1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/api/src/app/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MenuResolver } from './resolvers/menu.resolver';
import { OrganizationResolver } from './resolvers/organization.resolver';
import { ProductResolver } from './resolvers/product.resolver';
import { SalesInvoiceResolver } from './resolvers/sales.invoice.resolver';
import { TaxResolver } from './resolvers/tax.resolver';

export const resolvers = [
AppResolver,
Expand All @@ -39,4 +40,5 @@ export const resolvers = [
FactoringContractResolver,
AttachmentResolver,
MailResolver,
TaxResolver,
];
36 changes: 36 additions & 0 deletions apps/api/src/app/resolvers/tax.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Inject, UseGuards } from '@nestjs/common';
import { Args, Int, Mutation, Query, Resolver } from '@nestjs/graphql';
import { InjectEntityManager } from '@nestjs/typeorm';
import { EntityManager } from 'typeorm';
import { CurrentUser, GqlAuthGuard } from '../../auth';
import { TaxModel, TaxService, TaxServiceKey } from '../../model';
import { Tax } from '../../model/generated/entities/Tax';
import { TaxSaveArgs } from '../saveArgs/tax.save.args';

@Resolver(() => Tax)
@UseGuards(GqlAuthGuard)
export class TaxResolver {
constructor(
@Inject(TaxServiceKey) protected readonly taxService: TaxService,
@InjectEntityManager()
private readonly entityManager: EntityManager,
) {}

@Query(() => [Tax])
async taxes() {
return await this.taxService.loadEntities(this.entityManager);
}

@Query(() => Tax)
async tax(@Args('id', { type: () => Int }) id: number) {
return await this.taxService.loadEntityById(this.entityManager, id);
}

@Mutation(() => Tax)
async saveTax(
@Args('args') objData: TaxSaveArgs,
@CurrentUser() user,
): Promise<TaxModel> {
return await this.taxService.save(this.entityManager, objData, user);
}
}
13 changes: 13 additions & 0 deletions apps/api/src/app/saveArgs/tax.save.args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Field, InputType } from '@nestjs/graphql';
import { TaxSaveArgsModel } from '../../model';
import { BaseSaveArgs } from './base.save.args';

@InputType()
export class TaxSaveArgs extends BaseSaveArgs implements TaxSaveArgsModel {
@Field()
displayName: string;
@Field()
ratePercent: number;
@Field()
isStandard: boolean;
}
7 changes: 6 additions & 1 deletion apps/api/src/model/generated/entities/Tax.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field } from '@nestjs/graphql';
import { Field, ObjectType } from '@nestjs/graphql';
import {
Column,
Entity,
Expand All @@ -12,8 +12,10 @@ import { SalesInvoiceLine } from './SalesInvoiceLine';
import { User } from './User';

@Entity('tax', { schema: 'public' })
@ObjectType()
export class Tax {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
@Field()
id: number;

@Column('timestamp without time zone', {
Expand All @@ -37,12 +39,15 @@ export class Tax {
isCurrent: boolean;

@Column('character varying', { name: 'displayName' })
@Field()
displayName: string;

@Column('integer', { name: 'ratePercent' })
@Field()
ratePercent: number;

@Column('boolean', { name: 'isStandard' })
@Field()
isStandard: boolean;

@OneToMany(
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/model/lib/document.numbering.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class DocumentNumberingService {
organization: OrganizationModel,
): Promise<string> {
const model = await manager.getRepository(DocumentNumberSequence).findOne({
where: { forType: modelCtor.name, organization },
where: { forType: modelCtor.name, organization: { id: organization.id } },
order: { id: 'DESC' },
});
const result = model.current;
Expand Down
11 changes: 9 additions & 2 deletions apps/api/src/model/lib/sales.invoice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,15 @@ export class SalesInvoiceService extends BaseEntityService<
currentUser: UserModel,
): Promise<SalesInvoiceModel> => {
const source = await this.loadEntityById(transactionalEntityManager, id);
source.isDraft = true;
return this.save(transactionalEntityManager, source, currentUser);
const copy = {
...source,
id: null,
isDraft: true,
documentNo: null,
printed: false,
isCalculated: false,
};
return this.save(transactionalEntityManager, copy, currentUser);
};

publish = async (
Expand Down
1 change: 1 addition & 0 deletions build_deploy_dokku.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git push dokku HEAD:main --force

0 comments on commit 18386d1

Please sign in to comment.