-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add internal tags to sdk * fix naming --------- Co-authored-by: Jim Power <[email protected]> Co-authored-by: Cheng Yu <[email protected]>
- Loading branch information
1 parent
d45003b
commit 6c0a2f3
Showing
22 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.