Skip to content

Commit

Permalink
add internal tags to sdk (#680)
Browse files Browse the repository at this point in the history
* add internal tags to sdk

* fix naming

---------

Co-authored-by: Jim Power <[email protected]>
Co-authored-by: Cheng Yu <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent d45003b commit 6c0a2f3
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 0 deletions.
3 changes: 3 additions & 0 deletions javascript/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { ShipmentMethod } from './shipment_method.js';
import { User } from './user.js';
import { UserCompany } from './user_company.js';
import { PaymentDevice } from './payment_device.js';
import { InternalTag } from './internal_tag.js';


export function Company() {
this.resource = '/companies';
Expand Down Expand Up @@ -94,6 +96,7 @@ export function Company() {
addPropertyTo(this, 'aiContext');
addPropertyTo(this, 'internalUseNotes');
addPropertyTo(this, 'internalUseAiContext');
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (success, error, embed, as_domain) {
var data = serialise(this),
Expand Down
2 changes: 2 additions & 0 deletions javascript/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Menu } from './menu.js';
import { SupplyDomain } from './supply_domain.js';
import { SeoDomainPage } from './seo_domain_page.js';
import { User, Users } from './user.js';
import { InternalTag } from './internal_tag.js';

export function Domain() {
this.resource = '/domains';
Expand Down Expand Up @@ -76,6 +77,7 @@ export function Domain() {
addPropertyTo(this, 'domainInvitations', DomainInvitation);
addPropertyTo(this, 'jobsAssignees', User);
addPropertyTo(this, 'tags', DomainTag);
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (success, error, embed, as_domain) {
var data = serialise(this),
Expand Down
90 changes: 90 additions & 0 deletions javascript/internal_tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { generateUUID } from './uuid.js';
import { addPropertyTo, serialise, create, fromJson, patchOne, deleteOne,
fromJsonList, getList, enumerateFiles, getOne } from './model.js';
import { Company } from './company.js';
import { Domain } from './domain.js';
import { Invoice } from './invoice.js';
import { Job } from './job.js';
import { Product } from './product.js';
import { Shipment } from './shipment.js';
import { Theme } from './theme.js';
import { User } from './user.js';

export function InternalTag() {
this.resource = '/internal_tags';
this.json = 'internalTag';
this.temporaryId = generateUUID();

addPropertyTo(this, 'id');
addPropertyTo(this, 'name');
addPropertyTo(this, 'description');
addPropertyTo(this, 'colour');
addPropertyTo(this, 'companies', Company);
addPropertyTo(this, 'domains', Domain);
addPropertyTo(this, 'invoices', Invoice);
addPropertyTo(this, 'jobs', Job);
addPropertyTo(this, 'products', Product);
addPropertyTo(this, 'shipments', Shipment);
addPropertyTo(this, 'themes', Theme);
addPropertyTo(this, 'users', User)

this.create = function (success, error, embed, domainId) {
var data = serialise(this),
self = this;
function handleResponse(result) {
success(fromJson(self, result[self.json]));
}
create({resource: this.resource,
parameters: data[0],
files: enumerateFiles(data[1]),
success: handleResponse,
error: error,
embed: embed,
as_domain: domainId});
};

this.get = function (success, error) {
var self = this;
function handleResponse(result) {
success(fromJson(self, result[self.json],
{makesDirty: false}));
}
getOne({resource: this.resource,
id: this.id(),
success: handleResponse,
error: error});
};

this.patch = function (success, error, embed) {
var self = this,
data = serialise(this)[0];
function handleResponse(result) {
success(fromJson(self, result[self.json],
{makesDirty: false}));
}
patchOne({resource: this.resource,
id: this.id(),
success: handleResponse,
error: error,
data: data,
embed: embed});
};

this.destroy = function (success, error) {
deleteOne(this.resource + "/" + this.id(), success, error);
};
}

export function InternalTags() {
this.resource = '/internal_tags';
this.json = 'internalTags';
this.single = InternalTag;

this.get = function (success, error, parameters) {
var self = this;
function handleResponse(result) {
success(fromJsonList(self, result, {makesDirty: false}));
}
getList(this.resource, handleResponse, error, parameters);
};
}
2 changes: 2 additions & 0 deletions javascript/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MerchiFile } from './merchi_file.js';
import { Quote } from './quote.js';
import { Payment } from './payment.js';
import { Job } from './job.js';
import { InternalTag } from './internal_tag.js';

export function Invoice() {
this.resource = '/invoices';
Expand Down Expand Up @@ -67,6 +68,7 @@ export function Invoice() {
addPropertyTo(this, 'isCompletelyPaid');
addPropertyTo(this, 'shipments', Shipment);
addPropertyTo(this, 'shopifyOrderId');
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (success, error, embed, asDomain) {
var data = serialise(this),
Expand Down
2 changes: 2 additions & 0 deletions javascript/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { User } from './user.js';
import { Variation } from './variation.js';
import { VariationsGroup } from './variations_group.js';
import { JobComment } from './job_comment.js';
import { InternalTag } from './internal_tag.js';


export function Job() {
Expand Down Expand Up @@ -125,6 +126,7 @@ export function Job() {
addPropertyTo(this, 'shopifyShopUrl');
addPropertyTo(this, 'shopifyOrderId');
addPropertyTo(this, 'shopifyOrderLineItemId');
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (
success, error, embed, asDomain, withRights) {
Expand Down
3 changes: 3 additions & 0 deletions javascript/merchi.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { VariationFieldsOption } from './variation_fields_option.js';
import { VariationsGroup } from './variations_group.js';
import { QuoteItem, QuoteItems } from './quote_item.js';
import { Quotes, Quote } from './quote.js';
import { InternalTag, InternalTags } from './internal_tag.js';

export function merchi(backendUri, websocketUri) {
getGlobal().merchiJsonpHandlers = {};
Expand Down Expand Up @@ -941,6 +942,8 @@ export function merchi(backendUri, websocketUri) {
'inventories': new Inventories(),
'InventoryUnitVariation': InventoryUnitVariation,
'matchiingInventory': MatchingInventory,
'InternalTag': InternalTag,
'internalTags': new InternalTags(),
'Invoice': Invoice,
'invoices': new Invoices(),
'Job': Job,
Expand Down
2 changes: 2 additions & 0 deletions javascript/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SupplyDomain } from './supply_domain.js';
import { User } from './user.js';
import { Job } from './job.js';
import { SeoDomainPage } from './seo_domain_page.js';
import { InternalTag } from './internal_tag.js';

export function Product() {
this.resource = '/products';
Expand Down Expand Up @@ -109,6 +110,7 @@ export function Product() {
addPropertyTo(this, 'aiContext');
addPropertyTo(this, 'internalUseNotes');
addPropertyTo(this, 'internalUseAiContext');
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (success, error, embed, asDomain) {
var data = serialise(this),
Expand Down
2 changes: 2 additions & 0 deletions javascript/shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Job } from './job.js';
import { MerchiFile } from './merchi_file.js';
import { ShipmentItem } from './shipment_item.js';
import { ShipmentMethod } from './shipment_method.js';
import { InternalTag } from './internal_tag.js';

export function Shipment() {
this.resource = '/shipments';
Expand Down Expand Up @@ -56,6 +57,7 @@ export function Shipment() {
addPropertyTo(this, 'tags', DomainTag);
addPropertyTo(this, 'shipmentItems', ShipmentItem)
addPropertyTo(this, 'shipmentMethod', ShipmentMethod);
addPropertyTo(this, 'internalTags', InternalTag);

this.get = function (success, error, embed) {
var self = this;
Expand Down
2 changes: 2 additions & 0 deletions javascript/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Component } from './component.js';
import { Domain } from './domain.js';
import { Page } from './page.js';
import { User } from './user.js';
import { InternalTag } from './internal_tag.js';

export function Theme() {
this.resource = '/themes';
Expand Down Expand Up @@ -89,6 +90,7 @@ export function Theme() {
addPropertyTo(this, 'author', User);
addPropertyTo(this, 'domain', Domain);
addPropertyTo(this, 'defaultForDomainType');
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (success, error, embed, as_domain) {
var self = this,
Expand Down
2 changes: 2 additions & 0 deletions javascript/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Domain } from './domain.js';
import { MerchiFile } from './merchi_file.js';
import { SystemRole } from './system_role.js';
import { UserCompany } from './user_company.js';
import { InternalTag } from './internal_tag.js';

export function User() {
this.resource = '/users';
Expand Down Expand Up @@ -51,6 +52,7 @@ export function User() {
addPropertyTo(this, 'aiContext');
addPropertyTo(this, 'internalUseNotes');
addPropertyTo(this, 'internalUseAiContext');
addPropertyTo(this, 'internalTags', InternalTag);

this.create = function (success, error, embed, as_domain) {
var self = this,
Expand Down
40 changes: 40 additions & 0 deletions python/internal_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sdk.python.entities
from sdk.python.companies import Company
from sdk.python.domains import Domain
from sdk.python.invoices import Invoice
from sdk.python.jobs import Job
from sdk.python.products import Product
from sdk.python.entities import Property
from sdk.python.shipments import Shipment
from sdk.python.themes import Theme
from sdk.python.users import User


class InternalTag(sdk.python.entities.Entity):

json_name = 'internalTag'
resource = '/internal_tags/'

id = Property(int)
name = Property(str)
# colour is in RRGGBB format.
colour = Property(int)
description = Property(str)

companies = Property(Company, backref="internal_tags")
domains = Property(Domain, backref="internal_tags")
invoices = Property(Invoice, backref="internal_tags")
jobs = Property(Job, backref="internal_tags")
products = Property(Product, backref="internal_tags")
shipments = Property(Shipment, backref="internal_tags")
themes = Property(Theme, backref="internal_tags")
users = Property(User, backref="internal_tags")


class InternalTags(sdk.python.entities.Resource):

entity_class = InternalTag
json_name = 'internalTags'


internal_tags = InternalTags()
4 changes: 4 additions & 0 deletions typescript/src/entities/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Domain } from './domain';
import { EmailAddress } from './email_address';
import { Entity } from '../entity';
import { MerchiFile } from './file';
import { InternalTag } from './internal_tag';
import { Invoice } from './invoice';
import { Job } from './job';
import { PhoneNumber } from './phone_number';
Expand Down Expand Up @@ -188,6 +189,9 @@ export class Company extends Entity {
@Company.property()
public country?: string;

@Company.property({arrayType: 'InternalTag'})
public internalTags?: InternalTag[];

@Company.property({type: MerchiFile})
public logo?: MerchiFile | null;

Expand Down
4 changes: 4 additions & 0 deletions typescript/src/entities/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DomainTag } from './domain_tag';
import { EnrolledDomain } from './enrolled_domain';
import { Entity } from '../entity';
import { MerchiFile } from './file';
import { InternalTag } from './internal_tag';
import { Invoice } from './invoice';
import { Job } from './job';
import { Menu } from './menu';
Expand Down Expand Up @@ -164,6 +165,9 @@ export class Domain extends Entity {
@Domain.property()
public activeTheme?: Theme;

@Domain.property({arrayType: 'InternalTag'})
public internalTags?: InternalTag[];

@Domain.property({arrayType: 'DomainTag'})
public tags?: DomainTag[];

Expand Down
7 changes: 7 additions & 0 deletions typescript/src/entities/internal_tag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Merchi } from '../merchi';

test('can make InternalTag', () => {
const merchi = new Merchi();
const internalTag = new merchi.InternalTag();
expect(internalTag).toBeTruthy();
});
51 changes: 51 additions & 0 deletions typescript/src/entities/internal_tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Company } from './company';
import { Domain } from './domain';
import { Entity } from '../entity';
import { Invoice } from './invoice';
import { Job } from './job';
import { Product } from './product';
import { Shipment } from './shipment';
import { Theme } from './theme';
import { User } from './user';

export class InternalTag extends Entity {
protected static resourceName = 'internal_tags';
protected static singularName = 'internalTag';
protected static pluralName = 'internalTags';

@InternalTag.property()
public id?: number;

@InternalTag.property()
public colour?: number;

@InternalTag.property()
public name?: string;

@InternalTag.property()
public description?: string;

@InternalTag.property({arrayType: 'Company'})
public companies?: Company[];

@InternalTag.property({arrayType: 'Domain'})
public domains?: Domain[];

@InternalTag.property({arrayType: 'Job'})
public jobs?: Job[];

@InternalTag.property({arrayType: 'Product'})
public products?: Product[];

@InternalTag.property({arrayType: 'Invoice'})
public invoices?: Invoice[];

@InternalTag.property({arrayType: 'Shipment'})
public shipments?: Shipment[];

@InternalTag.property({arrayType: 'Theme'})
public themes?: Theme[];

@InternalTag.property({arrayType: 'User'})
public users?: User[];
}
4 changes: 4 additions & 0 deletions typescript/src/entities/invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DomainTag } from './domain_tag';
import { EmailAddress } from './email_address';
import { Entity } from '../entity';
import { MerchiFile } from './file';
import { InternalTag } from './internal_tag';
import { Item } from './item';
import { Job } from './job';
import { Quote } from './quote';
Expand Down Expand Up @@ -152,6 +153,9 @@ export class Invoice extends Entity {
@Invoice.property({type: EmailAddress})
public clientCompanyEmail?: EmailAddress | null;

@Invoice.property({arrayType: 'InternalTag'})
public internalTags?: InternalTag[];

@Invoice.property({arrayType: 'DomainTag'})
public tags?: DomainTag[];

Expand Down
Loading

0 comments on commit 6c0a2f3

Please sign in to comment.