@chevre/domain 21.8.0-alpha.63 → 21.8.0-alpha.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.
@@ -1,6 +1,5 @@
1
1
  // tslint:disable:no-console
2
2
  import * as mongoose from 'mongoose';
3
- import * as util from 'util';
4
3
 
5
4
  import { chevre } from '../../../lib/index';
6
5
 
@@ -8,80 +7,76 @@ import { chevre } from '../../../lib/index';
8
7
 
9
8
  // tslint:disable-next-line:max-func-body-length
10
9
  async function main() {
10
+ const now = new Date();
11
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
12
 
13
13
  const offerRepo = new chevre.repository.Offer(mongoose.connection);
14
+ const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
15
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
14
16
 
15
- const cursor = offerRepo.getCursor(
17
+ const cursor = offerCatalogRepo.getCursor(
16
18
  {
17
19
  // 'project.id': { $eq: project.id }
18
20
  },
19
21
  {
20
22
  __v: 0,
21
23
  createdAt: 0,
22
- updatedAt: 0,
23
- offers: 0,
24
- availableAddOn: 0
24
+ updatedAt: 0
25
25
  }
26
26
  );
27
- console.log('offers found');
27
+ console.log('catalogs found');
28
28
 
29
29
  let i = 0;
30
30
  let updateCount = 0;
31
31
  await cursor.eachAsync(async (doc) => {
32
32
  i += 1;
33
- const { _id, ...unitPriceOffer } =
34
- <chevre.factory.unitPriceOffer.IUnitPriceOffer & { _id: string }>doc.toObject();
33
+ const { _id, ...offerCatalog } = <chevre.factory.offerCatalog.IOfferCatalog & { _id: string }>doc.toObject();
34
+ const aggregateOfferIds = offerCatalog.itemListElement.map((element) => element.id);
35
35
 
36
- let alreadyMigrated = false;
37
- const aggregateOffer = await offerRepo.findAggregateOfferById({
38
- project: { id: unitPriceOffer.project.id },
39
- id: String(unitPriceOffer.id)
40
- });
41
- let offerByAggregateOffer = aggregateOffer.offers.shift();
42
- // alreadyMigrated = true;
43
- console.log(unitPriceOffer, offerByAggregateOffer);
44
-
45
- // 比較のために補完
46
- if (offerByAggregateOffer !== undefined) {
47
- offerByAggregateOffer = {
48
- ...offerByAggregateOffer,
49
- additionalProperty: (Array.isArray(offerByAggregateOffer.additionalProperty))
50
- ? offerByAggregateOffer.additionalProperty : [],
51
- addOn: (Array.isArray(offerByAggregateOffer.addOn))
52
- ? offerByAggregateOffer.addOn : [],
53
- availableAtOrFrom: (Array.isArray(offerByAggregateOffer.availableAtOrFrom))
54
- ? offerByAggregateOffer.availableAtOrFrom : []
55
- };
56
- // delete (<any>offerByAggregateOffer).$unset;
57
- }
58
-
59
- if (util.isDeepStrictEqual(unitPriceOffer, offerByAggregateOffer)) {
60
- alreadyMigrated = true;
61
- } else {
62
- console.error(unitPriceOffer, offerByAggregateOffer);
63
- throw new Error('not matched');
64
- }
36
+ // 記載カタログの追加された単価オファーの存在を検証
37
+ const existingOffers = await offerRepo.search(
38
+ {
39
+ project: { id: { $eq: offerCatalog.project.id } },
40
+ parentOffer: {
41
+ // id: { $in: aggregateOfferIds },
42
+ includedInDataCatalog: { id: { $in: [String(offerCatalog.id)] } }
43
+ }
44
+ },
45
+ { id: 1 }
46
+ );
47
+ console.log(existingOffers.length, 'offers found', offerCatalog.project.id, offerCatalog.id, offerCatalog.identifier, i);
48
+ const alreadyMigrated = aggregateOfferIds.length === existingOffers.length;
65
49
 
66
50
  if (alreadyMigrated) {
67
- console.log('already exist.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
51
+ console.log('already synced.', offerCatalog.project.id, offerCatalog.id, offerCatalog.identifier, i);
68
52
  } else {
69
- console.log('updating...', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
70
- // await offerRepo.saveSyncTask({
71
- // project: { id: unitPriceOffer.project.id },
72
- // id: { $in: [String(unitPriceOffer.id)] },
73
- // identifier: { $in: [] },
74
- // isDeleted: false,
75
- // typeOf: chevre.factory.offerType.Offer,
76
- // options: { emitImmediately: false }
77
- // });
53
+ console.log('creating task...', offerCatalog.project.id, offerCatalog.id, offerCatalog.identifier, i);
54
+ const syncTaskData: chevre.factory.task.onResourceUpdated.IData4common = {
55
+ typeOf: 'CategoryCode',
56
+ id: [String(offerCatalog.id)],
57
+ isNew: false,
58
+ isDeleted: false,
59
+ project: { id: offerCatalog.project.id },
60
+ useInform: false
61
+ };
62
+ const syncTask: chevre.factory.task.IAttributes<chevre.factory.taskName.OnResourceUpdated> = {
63
+ data: syncTaskData,
64
+ executionResults: [],
65
+ name: chevre.factory.taskName.OnResourceUpdated,
66
+ numberOfTried: 0,
67
+ project: offerCatalog.project,
68
+ remainingNumberOfTries: 1,
69
+ runsAt: now,
70
+ status: chevre.factory.taskStatus.Ready
71
+ };
72
+ await taskRepo.saveMany([syncTask], { emitImmediately: false });
78
73
  updateCount += 1;
79
- console.log('updated.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
74
+ console.log('task saved.', offerCatalog.project.id, offerCatalog.id, offerCatalog.identifier, i);
80
75
  }
81
76
  });
82
77
 
83
- console.log(i, 'offers checked');
84
- console.log(updateCount, 'offers updated');
78
+ console.log(i, 'catalogs checked');
79
+ console.log(updateCount, 'catalogs synced');
85
80
  }
86
81
 
87
82
  main()
@@ -61,6 +61,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
61
61
  alternateName?: any;
62
62
  description?: any;
63
63
  itemOffered?: any;
64
+ dateSynced?: Date | undefined;
64
65
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
65
66
  typeOf: string;
66
67
  additionalProperty: any[];
@@ -72,6 +73,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
72
73
  alternateName?: any;
73
74
  description?: any;
74
75
  itemOffered?: any;
76
+ dateSynced?: Date | undefined;
75
77
  }>> & Omit<import("mongoose").FlatRecord<{
76
78
  typeOf: string;
77
79
  additionalProperty: any[];
@@ -83,6 +85,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
83
85
  alternateName?: any;
84
86
  description?: any;
85
87
  itemOffered?: any;
88
+ dateSynced?: Date | undefined;
86
89
  }> & Required<{
87
90
  _id: string;
88
91
  }>, never>>;
@@ -24,7 +24,8 @@ const schema = new mongoose_1.Schema({
24
24
  },
25
25
  itemListElement: [mongoose_1.SchemaTypes.Mixed],
26
26
  itemOffered: mongoose_1.SchemaTypes.Mixed,
27
- additionalProperty: [mongoose_1.SchemaTypes.Mixed]
27
+ additionalProperty: [mongoose_1.SchemaTypes.Mixed],
28
+ dateSynced: Date // 追加(2023-09-13~)
28
29
  }, {
29
30
  collection: 'offerCatalogs',
30
31
  id: true,
@@ -32,6 +32,13 @@ export declare class MongoRepository {
32
32
  constructor(connection: Connection);
33
33
  static CREATE_MONGO_CONDITIONS(params: factory.offerCatalog.ISearchConditions): any[];
34
34
  save(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
35
+ /**
36
+ * 同期日時を更新する
37
+ */
38
+ updateDateSynced(params: {
39
+ id: string;
40
+ dateSynced: Date;
41
+ }): Promise<void>;
35
42
  updateManyById(params: {
36
43
  id: {
37
44
  $in: string[];
@@ -144,6 +144,15 @@ class MongoRepository {
144
144
  return doc.toObject();
145
145
  });
146
146
  }
147
+ /**
148
+ * 同期日時を更新する
149
+ */
150
+ updateDateSynced(params) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ yield this.offerCatalogModel.updateOne({ _id: params.id }, { $set: { dateSynced: params.dateSynced } })
153
+ .exec();
154
+ });
155
+ }
147
156
  updateManyById(params) {
148
157
  return __awaiter(this, void 0, void 0, function* () {
149
158
  if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
@@ -36,8 +36,6 @@ function syncOfferCatalog(params) {
36
36
  id: offerCatalogId,
37
37
  project: { id: params.project.id }
38
38
  });
39
- // tslint:disable-next-line:no-console
40
- console.log('onOfferCatalog', offerCatalogId, ' updated.', itemListElement.length, 'itemListElement found.', itemListElement);
41
39
  const aggregateOfferIds = itemListElement.map((element) => element.id);
42
40
  // カタログを含み、かつ、新しいカタログに含まれない集計オファーからカタログを除外
43
41
  yield repos.aggregateOffer.pullIncludedInDataCatalog(Object.assign({ project: { id: params.project.id }, $pull: {
@@ -53,6 +51,8 @@ function syncOfferCatalog(params) {
53
51
  }
54
52
  });
55
53
  }
54
+ // 同期済記録を補完
55
+ yield repos.offerCatalog.updateDateSynced({ id: offerCatalogId, dateSynced: new Date() });
56
56
  }
57
57
  }
58
58
  });
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.8.0-alpha.63"
120
+ "version": "21.8.0-alpha.64"
121
121
  }