Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F8922489
reference-field.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
reference-field.ts
View Options
/*
The class has a dual nature, developer has a possibility to refer to it
as if it was a string e.g.:
console.log(item.reference_field) // 'SomeId'
but (s)he also can use it as a container for item which is referenced e.g.:
console.log(item.reference_field.name) // 'Some cool name'
*/
import
Item
from
"../response/item"
;
export
function
make
(
attachments
:
{
[
id
:
string
]
:
Item
},
fieldsWithAttachments
:
{
[
field_name
:
string
]
:
{}
},
id
:
string
|
any
,
field_name
:
string
)
{
return
new
ReferenceField
(
{
attachments
,
fieldsWithAttachments
,
field_name
},
id
.
toString
()
);
}
export
default
class
ReferenceField
extends
String
{
_value
:
string
;
[
field
:
string
]
:
any
;
constructor
(
attachments_params
:
{
attachments
:
any
;
fieldsWithAttachments
:
any
;
field_name
?:
string
;
},
id
:
string
)
{
super
(
id
);
this
.
_value
=
id
;
const
body
=
this
.
extractAttachmentsForId
(
attachments_params
);
for
(
let
field
of
Object
.
keys
(
body
))
{
this
[
field
]
=
body
[
field
];
}
}
extractAttachmentsForId
({
attachments
,
fieldsWithAttachments
,
}
:
{
attachments
:
{
[
id
:
string
]
:
Item
};
fieldsWithAttachments
:
{
[
field_name
:
string
]
:
{}
};
})
{
const
body
=
attachments
[
this
.
_value
];
for
(
let
name
of
Object
.
keys
(
fieldsWithAttachments
))
{
let
id
=
body
[
name
];
body
[
name
]
=
make
(
attachments
,
fieldsWithAttachments
[
name
],
id
,
name
);
}
return
body
;
}
toString
()
{
return
this
.
_value
;
}
valueOf
()
{
return
this
.
_value
;
}
toJSON
()
{
return
this
.
_value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Sep 20, 14:40 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
924436
Default Alt Text
reference-field.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment