@nina-protocol/nina-db 0.0.62 → 0.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/models/Release.js
CHANGED
|
@@ -6,6 +6,7 @@ import Account from './Account.js';
|
|
|
6
6
|
import Exchange from './Exchange.js';
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
|
+
import Tag from './Tag.js';
|
|
9
10
|
import axios from 'axios';
|
|
10
11
|
import { customAlphabet } from 'nanoid';
|
|
11
12
|
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
@@ -95,23 +96,27 @@ export default class Release extends Model {
|
|
|
95
96
|
price: `${price}`,
|
|
96
97
|
paymentMint,
|
|
97
98
|
});
|
|
99
|
+
if (metadata.properties.tags) {
|
|
100
|
+
for await (let tag of metadata.properties.tags) {
|
|
101
|
+
const tagRecord = await Tag.findOrCreate(tag);
|
|
102
|
+
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
98
105
|
await this.processRevenueShares(releaseAccount, release);
|
|
99
106
|
tweetNewRelease(metadata, publisherId, slug);
|
|
100
107
|
return release;
|
|
101
108
|
};
|
|
102
109
|
static processRevenueShares = async (releaseData, releaseRecord) => {
|
|
103
|
-
console.log('processRevenueShares', releaseData, releaseRecord);
|
|
104
110
|
const royaltyRecipients = releaseData.account?.royaltyRecipients || releaseData.royaltyRecipients;
|
|
105
111
|
for await (let recipient of royaltyRecipients) {
|
|
106
112
|
try {
|
|
107
113
|
if (recipient.recipientAuthority.toBase58() !== "11111111111111111111111111111111") {
|
|
108
114
|
const recipientAccount = await Account.findOrCreate(recipient.recipientAuthority.toBase58());
|
|
109
115
|
const revenueShares = (await recipientAccount.$relatedQuery('revenueShares')).map(revenueShare => revenueShare.id);
|
|
110
|
-
|
|
111
|
-
if (!revenueShares.includes(releaseRecord.id) && recipient.percentShares > 0) {
|
|
116
|
+
if (!revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() > 0) {
|
|
112
117
|
await Account.relatedQuery('revenueShares').for(recipientAccount.id).relate(releaseRecord.id);
|
|
113
118
|
}
|
|
114
|
-
else if (revenueShares.includes(releaseRecord.id) && recipient.
|
|
119
|
+
else if (revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() === 0) {
|
|
115
120
|
await Account.relatedQuery('revenueShares').for(recipientAccount.id).unrelate().where('id', releaseRecord.id);
|
|
116
121
|
}
|
|
117
122
|
}
|
|
@@ -233,6 +238,18 @@ export default class Release extends Model {
|
|
|
233
238
|
},
|
|
234
239
|
to: 'accounts.id',
|
|
235
240
|
},
|
|
236
|
-
}
|
|
241
|
+
},
|
|
242
|
+
tags: {
|
|
243
|
+
relation: Model.ManyToManyRelation,
|
|
244
|
+
modelClass: Tag,
|
|
245
|
+
join: {
|
|
246
|
+
from: 'releases.id',
|
|
247
|
+
through: {
|
|
248
|
+
from: 'tags_content.releaseId',
|
|
249
|
+
to: 'tags_content.tagId',
|
|
250
|
+
},
|
|
251
|
+
to: 'tags.id',
|
|
252
|
+
},
|
|
253
|
+
},
|
|
237
254
|
});
|
|
238
255
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
export default class Tag extends Model {
|
|
3
|
+
static tableName = 'tags';
|
|
4
|
+
static idColumn = 'id';
|
|
5
|
+
static jsonSchema = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
required: ['value'],
|
|
8
|
+
properties: {
|
|
9
|
+
value: { type: 'string' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
async findOrCreate(value) {
|
|
13
|
+
let tag = await Tag.query().where('value', value).first();
|
|
14
|
+
if (!tag) {
|
|
15
|
+
tag = await Tag.query().insert({ value });
|
|
16
|
+
}
|
|
17
|
+
return tag;
|
|
18
|
+
}
|
|
19
|
+
async format() {
|
|
20
|
+
delete this.id;
|
|
21
|
+
}
|
|
22
|
+
static relationMappings = () => ({
|
|
23
|
+
posts: {
|
|
24
|
+
relation: Model.ManyToManyRelation,
|
|
25
|
+
modelClass: 'Post',
|
|
26
|
+
join: {
|
|
27
|
+
from: 'tags.id',
|
|
28
|
+
through: {
|
|
29
|
+
from: 'tags_content.tagId',
|
|
30
|
+
to: 'tags_content.postId',
|
|
31
|
+
},
|
|
32
|
+
to: 'posts.id',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
releases: {
|
|
36
|
+
relation: Model.ManyToManyRelation,
|
|
37
|
+
modelClass: 'Release',
|
|
38
|
+
join: {
|
|
39
|
+
from: 'tags.id',
|
|
40
|
+
through: {
|
|
41
|
+
from: 'tags_content.tagId',
|
|
42
|
+
to: 'tags_content.releaseId',
|
|
43
|
+
},
|
|
44
|
+
to: 'releases.id',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
package/package.json
CHANGED
package/src/models/Release.js
CHANGED
|
@@ -6,6 +6,7 @@ import Account from './Account.js';
|
|
|
6
6
|
import Exchange from './Exchange.js';
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
|
+
import Tag from './Tag.js';
|
|
9
10
|
import axios from 'axios';
|
|
10
11
|
import { customAlphabet } from 'nanoid';
|
|
11
12
|
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
@@ -106,23 +107,27 @@ export default class Release extends Model {
|
|
|
106
107
|
price: `${price}`,
|
|
107
108
|
paymentMint,
|
|
108
109
|
})
|
|
110
|
+
if (metadata.properties.tags) {
|
|
111
|
+
for await (let tag of metadata.properties.tags) {
|
|
112
|
+
const tagRecord = await Tag.findOrCreate(tag);
|
|
113
|
+
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
109
116
|
await this.processRevenueShares(releaseAccount, release);
|
|
110
117
|
tweetNewRelease(metadata, publisherId, slug);
|
|
111
118
|
return release;
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
static processRevenueShares = async (releaseData, releaseRecord) => {
|
|
115
|
-
console.log('processRevenueShares', releaseData, releaseRecord)
|
|
116
122
|
const royaltyRecipients = releaseData.account?.royaltyRecipients || releaseData.royaltyRecipients
|
|
117
123
|
for await (let recipient of royaltyRecipients) {
|
|
118
124
|
try {
|
|
119
125
|
if (recipient.recipientAuthority.toBase58() !== "11111111111111111111111111111111") {
|
|
120
126
|
const recipientAccount = await Account.findOrCreate(recipient.recipientAuthority.toBase58());
|
|
121
127
|
const revenueShares = (await recipientAccount.$relatedQuery('revenueShares')).map(revenueShare => revenueShare.id);
|
|
122
|
-
|
|
123
|
-
if (!revenueShares.includes(releaseRecord.id) && recipient.percentShares > 0) {
|
|
128
|
+
if (!revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() > 0) {
|
|
124
129
|
await Account.relatedQuery('revenueShares').for(recipientAccount.id).relate(releaseRecord.id);
|
|
125
|
-
} else if (revenueShares.includes(releaseRecord.id) && recipient.
|
|
130
|
+
} else if (revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() === 0) {
|
|
126
131
|
await Account.relatedQuery('revenueShares').for(recipientAccount.id).unrelate().where('id', releaseRecord.id);
|
|
127
132
|
}
|
|
128
133
|
}
|
|
@@ -249,6 +254,18 @@ export default class Release extends Model {
|
|
|
249
254
|
},
|
|
250
255
|
to: 'accounts.id',
|
|
251
256
|
},
|
|
252
|
-
}
|
|
257
|
+
},
|
|
258
|
+
tags: {
|
|
259
|
+
relation: Model.ManyToManyRelation,
|
|
260
|
+
modelClass: Tag,
|
|
261
|
+
join: {
|
|
262
|
+
from: 'releases.id',
|
|
263
|
+
through: {
|
|
264
|
+
from: 'tags_content.releaseId',
|
|
265
|
+
to: 'tags_content.tagId',
|
|
266
|
+
},
|
|
267
|
+
to: 'tags.id',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
253
270
|
})
|
|
254
271
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
|
|
3
|
+
export default class Tag extends Model {
|
|
4
|
+
static tableName = 'tags';
|
|
5
|
+
static idColumn = 'id';
|
|
6
|
+
static jsonSchema = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
required: ['value'],
|
|
9
|
+
properties: {
|
|
10
|
+
value: { type: 'string' },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async findOrCreate(value) {
|
|
15
|
+
let tag = await Tag.query().where('value', value).first();
|
|
16
|
+
if (!tag) {
|
|
17
|
+
tag = await Tag.query().insert({ value });
|
|
18
|
+
}
|
|
19
|
+
return tag;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async format () {
|
|
23
|
+
delete this.id
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static relationMappings = () => ({
|
|
27
|
+
posts: {
|
|
28
|
+
relation: Model.ManyToManyRelation,
|
|
29
|
+
modelClass: 'Post',
|
|
30
|
+
join: {
|
|
31
|
+
from: 'tags.id',
|
|
32
|
+
through: {
|
|
33
|
+
from: 'tags_content.tagId',
|
|
34
|
+
to: 'tags_content.postId',
|
|
35
|
+
},
|
|
36
|
+
to: 'posts.id',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
releases: {
|
|
40
|
+
relation: Model.ManyToManyRelation,
|
|
41
|
+
modelClass: 'Release',
|
|
42
|
+
join: {
|
|
43
|
+
from: 'tags.id',
|
|
44
|
+
through: {
|
|
45
|
+
from: 'tags_content.tagId',
|
|
46
|
+
to: 'tags_content.releaseId',
|
|
47
|
+
},
|
|
48
|
+
to: 'releases.id',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|