Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
turns out that when using union types with `undefined` the compiler will save the type as `Object` (more info: microsoft/TypeScript#12703), which isn't good for typeorm.
Instead, mark nullable props as optional.
  • Loading branch information
nitzantomer committed Mar 25, 2018
1 parent 08fa7c2 commit 93cd9f4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion scripts/src/models/offers.ts
Expand Up @@ -105,7 +105,7 @@ export class Asset extends CreationDateModel {
public offerId!: string;

@Column({ name: "owner_id", nullable: true })
public ownerId!: string | null; // User.id
public ownerId?: string; // User.id

@Column("simple-json")
public value!: AssetValue;
Expand Down
8 changes: 4 additions & 4 deletions scripts/src/models/orders.ts
Expand Up @@ -26,7 +26,7 @@ export class Order extends CreationDateModel {
public type!: OfferType;

@Column("simple-json", { name: "blockchain_data", nullable: true })
public blockchainData!: BlockchainData;
public blockchainData?: BlockchainData;

@Column({ name: "user_id" })
public userId!: string;
Expand All @@ -38,10 +38,10 @@ export class Order extends CreationDateModel {
public meta!: OrderMeta;

@Column("simple-json", { nullable: true }) // the asset or JWT payment confirmation
public value: OrderValue | undefined;
public value?: OrderValue;

@Column("simple-json", { nullable: true })
public error: OrderError | undefined;
public error?: OrderError;

@Column()
public amount!: number;
Expand All @@ -50,7 +50,7 @@ export class Order extends CreationDateModel {
public status!: OrderStatus;

@Column({ name: "completion_date", nullable: true })
public completionDate!: Date;
public completionDate?: Date;
}

export type OpenOrder = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/models/users.ts
Expand Up @@ -18,7 +18,7 @@ export class User extends CreationDateModel {
public walletAddress!: string;

@Column({ name: "activated_date", nullable: true })
public activatedDate!: Date;
public activatedDate?: Date;

public get activated(): boolean {
return !!this.activatedDate;
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/public/routes/index.ts
Expand Up @@ -51,7 +51,7 @@ function router(): ExtendedRouter {
const token = await authenticate(req);
const user = await db.User.findOneById(token.userId);
// XXX scopes should be per token and should not consider user data
if (scopes.includes(AuthScopes.TOS) && (!user || !user.activated || token.createdDate < user.activatedDate)) {
if (scopes.includes(AuthScopes.TOS) && (!user || !user.activated || token.createdDate < user.activatedDate!)) {
throw Error("user did not approve TOS or using a pre activated token");
}
req.context = { user, token };
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/public/services/orders.ts
Expand Up @@ -56,7 +56,7 @@ function orderDbToApi(order: db.Order, logger: LoggerInstance): Order {
result: order.value,
error: order.error,
completion_date: (order.completionDate || order.createdDate).toISOString(), // XXX should we separate the dates?
blockchain_data: order.blockchainData,
blockchain_data: order.blockchainData!,
offer_type: order.type,
title: order.meta.title,
description: order.meta.description,
Expand Down

0 comments on commit 93cd9f4

Please sign in to comment.