Skip to content

Commit

Permalink
refactor: Change iconUrl to icon, make transaction name required, mak…
Browse files Browse the repository at this point in the history
…e birthDate optional on registration and deprecate
  • Loading branch information
filipw01 committed Mar 21, 2021
1 parent f2c4267 commit d274834
Show file tree
Hide file tree
Showing 18 changed files with 317 additions and 133 deletions.
6 changes: 3 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Account {
currency: String!
cycleTransaction: [CycleTransaction!]!
description: String
iconUrl: String!
icon: String!
id: String!
interestRate: Float
name: String!
Expand Down Expand Up @@ -42,7 +42,7 @@ type BudgetMembership {
type Category {
color: String!
cycleTransactions: [CycleTransaction!]!
iconUrl: String!
icon: String!
id: String!
limit: Float
name: String!
Expand Down Expand Up @@ -72,7 +72,7 @@ type Debt {
currency: String!
description: String
endDate: String!
iconUrl: String!
icon: String!
id: String!
interestRate: Float
name: String!
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Account extends BaseEntity {

@Field()
@Column("varchar")
iconUrl: string;
icon: string;

@Field()
@Column("varchar")
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Category extends BaseEntity {

@Field()
@Column("varchar")
iconUrl: string;
icon: string;

@Field()
@Column("varchar")
Expand Down
4 changes: 2 additions & 2 deletions src/entities/CycleTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class CycleTransaction extends BaseEntity {
@PrimaryGeneratedColumn("uuid")
id: string;

@Field({ nullable: true })
@Column("varchar", { nullable: true })
@Field()
@Column("varchar")
name: string;

@Field({ nullable: true })
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Debt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Debt extends BaseEntity {

@Field()
@Column("varchar")
iconUrl: string;
icon: string;

@Field()
@Column("varchar")
Expand Down
4 changes: 2 additions & 2 deletions src/entities/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class Transaction extends BaseEntity {
@PrimaryGeneratedColumn("uuid")
id: string;

@Field({ nullable: true })
@Column("varchar", { nullable: true })
@Field()
@Column("varchar")
name: string;

@Field()
Expand Down
6 changes: 3 additions & 3 deletions src/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class User extends BaseEntity {
@Column({ type: "varchar", unique: true })
email: string;

@Field()
@Column("date")
birthDate: string;
@Field({ nullable: true })
@Column("date", { nullable: true })
birthDate?: string;

@Field({ nullable: true })
@Column("varchar", { nullable: true })
Expand Down
245 changes: 194 additions & 51 deletions src/migrations/1604829618416-initial.ts

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/migrations/1611149526215-addToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ export class addToken1611149526215 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "user" ADD "token" uuid NOT NULL DEFAULT uuid_generate_v4()`
`ALTER TABLE "user"
ADD "token" uuid NOT NULL DEFAULT uuid_generate_v4()`
);
await queryRunner.query(
`ALTER TABLE "user" ADD CONSTRAINT "UQ_a854e557b1b14814750c7c7b0c9" UNIQUE ("token")`
`ALTER TABLE "user"
ADD CONSTRAINT "UQ_a854e557b1b14814750c7c7b0c9" UNIQUE ("token")`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" DROP CONSTRAINT "UQ_a854e557b1b14814750c7c7b0c9"`);
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "token"`);
await queryRunner.query(`ALTER TABLE "user"
DROP CONSTRAINT "UQ_a854e557b1b14814750c7c7b0c9"`);
await queryRunner.query(`ALTER TABLE "user"
DROP COLUMN "token"`);
}
}
41 changes: 41 additions & 0 deletions src/migrations/1616288112190-changeColumnsAndConstrains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class changeColumnsAndConstrains1616288112190 implements MigrationInterface {
name = "changeColumnsAndConstrains1616288112190";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "debt"
RENAME COLUMN "iconUrl" TO "icon"`);
await queryRunner.query(`ALTER TABLE "category"
RENAME COLUMN "iconUrl" TO "icon"`);
await queryRunner.query(`ALTER TABLE "account"
RENAME COLUMN "iconUrl" TO "icon"`);
await queryRunner.query(`ALTER TABLE "cycle_transaction"
ALTER COLUMN "name" SET NOT NULL`);
await queryRunner.query(`COMMENT ON COLUMN "cycle_transaction"."name" IS NULL`);
await queryRunner.query(`ALTER TABLE "user"
ALTER COLUMN "birthDate" DROP NOT NULL`);
await queryRunner.query(`COMMENT ON COLUMN "user"."birthDate" IS NULL`);
await queryRunner.query(`ALTER TABLE "transaction"
ALTER COLUMN "name" SET NOT NULL`);
await queryRunner.query(`COMMENT ON COLUMN "transaction"."name" IS NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`COMMENT ON COLUMN "transaction"."name" IS NULL`);
await queryRunner.query(`ALTER TABLE "transaction"
ALTER COLUMN "name" DROP NOT NULL`);
await queryRunner.query(`COMMENT ON COLUMN "user"."birthDate" IS NULL`);
await queryRunner.query(`ALTER TABLE "user"
ALTER COLUMN "birthDate" SET NOT NULL`);
await queryRunner.query(`COMMENT ON COLUMN "cycle_transaction"."name" IS NULL`);
await queryRunner.query(`ALTER TABLE "cycle_transaction"
ALTER COLUMN "name" DROP NOT NULL`);
await queryRunner.query(`ALTER TABLE "account"
RENAME COLUMN "icon" TO "iconUrl"`);
await queryRunner.query(`ALTER TABLE "category"
RENAME COLUMN "icon" TO "iconUrl"`);
await queryRunner.query(`ALTER TABLE "debt"
RENAME COLUMN "icon" TO "iconUrl"`);
}
}
4 changes: 2 additions & 2 deletions src/resolvers/AccountResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AccountResolver {
balance,
color,
currency,
iconUrl: icon,
icon,
type,
description,
owner: await User.findOne({ where: { id: userId } }),
Expand Down Expand Up @@ -93,7 +93,7 @@ export class AccountResolver {
currency,
description,
balance,
iconUrl: icon,
icon,
type,
color,
interestRate,
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/CategoryResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class CategoryResolver {
name,
limit,
color,
iconUrl: icon,
icon,
ownerBudget: owner.budget,
ownerUser: owner.user,
type,
Expand Down Expand Up @@ -122,7 +122,7 @@ export class CategoryResolver {
name,
limit,
color,
iconUrl: icon,
icon,
type,
});
await category.save();
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/CycleTransactionInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class CycleTransactionInput {

@InputType()
export class NewCycleTransactionInput {
@Field({ nullable: true })
@Field()
name: string;

@Field({ nullable: true })
Expand Down
18 changes: 7 additions & 11 deletions src/resolvers/DebtResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export class DebtResolver {
): Promise<NoMethods<Debt>> {
const debt = await Debt.findOne({
where: { id },
relations: [
...new Set([...getRelationSubfields(info.fieldNodes[0].selectionSet), "owner"])
]
relations: [...new Set([...getRelationSubfields(info.fieldNodes[0].selectionSet), "owner"])],
});
if (!debt) {
throw new ApolloError("No debt found");
Expand All @@ -46,11 +44,11 @@ export class DebtResolver {
balance,
color,
currency,
iconUrl: icon,
icon,
description,
interestRate,
endDate,
owner: await User.findOne({ where: { id: userId } })
owner: await User.findOne({ where: { id: userId } }),
}).save();
} catch (e) {
throw new ApolloError(e);
Expand All @@ -67,9 +65,7 @@ export class DebtResolver {
const { id, name, currency, description, balance, icon, color, interestRate } = options;
const debt = await Debt.findOne({
where: { id },
relations: [
...new Set([...getRelationSubfields(info.fieldNodes[0].selectionSet), "owner"])
]
relations: [...new Set([...getRelationSubfields(info.fieldNodes[0].selectionSet), "owner"])],
});
if (!debt) {
throw new ApolloError("There is no debt with that id");
Expand All @@ -83,9 +79,9 @@ export class DebtResolver {
currency,
description,
balance,
iconUrl: icon,
icon,
color,
interestRate
interestRate,
});
return { ...(await debt.save()), id };
} catch (e) {
Expand All @@ -102,7 +98,7 @@ export class DebtResolver {
): Promise<NoMethods<Debt>> {
const debt = await Debt.findOne({
where: { id },
relations: [...new Set([...getRelationSubfields(info.fieldNodes[0].selectionSet), "owner"])]
relations: [...new Set([...getRelationSubfields(info.fieldNodes[0].selectionSet), "owner"])],
});
if (!debt) {
throw new ApolloError("There is no debt with that id");
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/TransactionInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class TransactionInput {

@InputType()
export class NewTransactionInput {
@Field({ nullable: true })
@Field()
name: string;

@Field()
Expand Down
6 changes: 3 additions & 3 deletions src/resolvers/UserInput.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { InputType, Field } from "type-graphql";

@InputType()
export class UsernamePasswordInput {
export class NewUserInput {
@Field()
email: string;
@Field()
name: string;
@Field()
password: string;
@Field()
birthDate: string;
@Field({ nullable: true, deprecationReason: "Use updateUser mutation instead" })
birthDate?: string;
}

@InputType()
Expand Down
6 changes: 3 additions & 3 deletions src/resolvers/UserResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApolloError } from "apollo-server-errors";
import { GraphQLResolveInfo } from "graphql";
import { User } from "../entities/User";
import { Context, NoMethods } from "../../types";
import { UpdateUserInput, UserInput, UsernamePasswordInput } from "./UserInput";
import { UpdateUserInput, UserInput, NewUserInput } from "./UserInput";
import { setToken } from "../utils/setToken";
import { unsetToken } from "../utils/unsetToken";
import { getRelationSubfields } from "../utils/getRelationSubfields";
Expand Down Expand Up @@ -64,7 +64,7 @@ export class UserResolver {

@Mutation(() => User)
async register(
@Arg("options") options: UsernamePasswordInput,
@Arg("options") options: NewUserInput,
@Ctx() { setCookies }: Context
): Promise<NoMethods<User>> {
const userWithSameEmail = await User.findOne({
Expand All @@ -87,7 +87,7 @@ export class UserResolver {
email,
name,
password: hashedPassword,
birthDate: birthDate,
birthDate,
}).save();
} catch (err) {
throw new ApolloError(err);
Expand Down
Loading

0 comments on commit d274834

Please sign in to comment.