@chevre/domain 23.0.0-alpha.8 → 23.0.0-alpha.9
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/example/src/chevre/product/findHasOfferCatalog.ts +27 -0
- package/example/src/chevre/roles/addAdminNotePermissionIfNotExists.ts +48 -0
- package/example/src/chevre/roles/{addAdminProductOfferPermissionIfNotExists.ts → addAdminProductReadPermissionIfNotExists.ts} +20 -19
- package/example/src/chevre/unsetUnnecessaryFields.ts +5 -7
- package/lib/chevre/repo/noteAboutOrder.d.ts +4 -11
- package/lib/chevre/repo/noteAboutOrder.js +16 -4
- package/lib/chevre/repo/productHasOfferCatalog.d.ts +42 -0
- package/lib/chevre/repo/productHasOfferCatalog.js +67 -0
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +14 -1
- package/package.json +1 -1
- package/example/src/chevre/unsetUnnecessaryFieldsInAction.ts +0 -50
- package/example/src/chevre/unsetUnnecessaryFieldsInTransaction.ts +0 -46
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const productHasOfferCatalogRepo = await chevre.repository.ProductHasOfferCatalog.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const offerCatalogs = (await productHasOfferCatalogRepo.findOfferCatalogs(
|
|
14
|
+
{
|
|
15
|
+
limit: 10,
|
|
16
|
+
page: 1,
|
|
17
|
+
project: { id: { $eq: project.id } },
|
|
18
|
+
product: { id: { $eq: '60c1c0031fb182000bed5eff' } }
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
// tslint:disable-next-line:no-null-keyword
|
|
22
|
+
console.dir(offerCatalogs, { depth: null });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
main()
|
|
26
|
+
.then()
|
|
27
|
+
.catch(console.error);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const roleNames = [
|
|
12
|
+
chevre.factory.role.organizationRole.RoleName.InventoryManager
|
|
13
|
+
// chevre.factory.role.organizationRole.RoleName.SellersOwner,
|
|
14
|
+
// chevre.factory.role.organizationRole.RoleName.SellersInventoryManager
|
|
15
|
+
];
|
|
16
|
+
const permissions = [
|
|
17
|
+
'admin.notes.*'
|
|
18
|
+
];
|
|
19
|
+
for (const roleName of roleNames) {
|
|
20
|
+
for (const permission of permissions) {
|
|
21
|
+
const result = await roleRepo.addPermissionIfNotExists({
|
|
22
|
+
roleName: { $eq: roleName },
|
|
23
|
+
permission
|
|
24
|
+
});
|
|
25
|
+
console.log('permission added.', result, roleName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// roleNames = [
|
|
30
|
+
// chevre.factory.role.organizationRole.RoleName.TicketClerk
|
|
31
|
+
// ];
|
|
32
|
+
// permissions = [
|
|
33
|
+
// 'admin.sellers.productOffers.read'
|
|
34
|
+
// ];
|
|
35
|
+
// for (const roleName of roleNames) {
|
|
36
|
+
// for (const permission of permissions) {
|
|
37
|
+
// const result = await roleRepo.addPermissionIfNotExists({
|
|
38
|
+
// roleName: { $eq: roleName },
|
|
39
|
+
// permission
|
|
40
|
+
// });
|
|
41
|
+
// console.log('permission added.', result, roleName);
|
|
42
|
+
// }
|
|
43
|
+
// }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
main()
|
|
47
|
+
.then()
|
|
48
|
+
.catch(console.error);
|
|
@@ -8,29 +8,14 @@ async function main() {
|
|
|
8
8
|
|
|
9
9
|
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const roleNames = [
|
|
12
12
|
chevre.factory.role.organizationRole.RoleName.InventoryManager,
|
|
13
13
|
chevre.factory.role.organizationRole.RoleName.SellersOwner,
|
|
14
|
-
chevre.factory.role.organizationRole.RoleName.SellersInventoryManager
|
|
15
|
-
];
|
|
16
|
-
let permissions = [
|
|
17
|
-
'admin.sellers.productOffers.*'
|
|
18
|
-
];
|
|
19
|
-
for (const roleName of roleNames) {
|
|
20
|
-
for (const permission of permissions) {
|
|
21
|
-
const result = await roleRepo.addPermissionIfNotExists({
|
|
22
|
-
roleName: { $eq: roleName },
|
|
23
|
-
permission
|
|
24
|
-
});
|
|
25
|
-
console.log('permission added.', result, roleName);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
roleNames = [
|
|
14
|
+
chevre.factory.role.organizationRole.RoleName.SellersInventoryManager,
|
|
30
15
|
chevre.factory.role.organizationRole.RoleName.TicketClerk
|
|
31
16
|
];
|
|
32
|
-
permissions = [
|
|
33
|
-
'admin.
|
|
17
|
+
const permissions = [
|
|
18
|
+
'admin.products.read'
|
|
34
19
|
];
|
|
35
20
|
for (const roleName of roleNames) {
|
|
36
21
|
for (const permission of permissions) {
|
|
@@ -41,6 +26,22 @@ async function main() {
|
|
|
41
26
|
console.log('permission added.', result, roleName);
|
|
42
27
|
}
|
|
43
28
|
}
|
|
29
|
+
|
|
30
|
+
// roleNames = [
|
|
31
|
+
// chevre.factory.role.organizationRole.RoleName.TicketClerk
|
|
32
|
+
// ];
|
|
33
|
+
// permissions = [
|
|
34
|
+
// 'admin.sellers.productOffers.read'
|
|
35
|
+
// ];
|
|
36
|
+
// for (const roleName of roleNames) {
|
|
37
|
+
// for (const permission of permissions) {
|
|
38
|
+
// const result = await roleRepo.addPermissionIfNotExists({
|
|
39
|
+
// roleName: { $eq: roleName },
|
|
40
|
+
// permission
|
|
41
|
+
// });
|
|
42
|
+
// console.log('permission added.', result, roleName);
|
|
43
|
+
// }
|
|
44
|
+
// }
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
main()
|
|
@@ -9,18 +9,16 @@ import { chevre } from '../../../lib/index';
|
|
|
9
9
|
async function main() {
|
|
10
10
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const noteRepo = await chevre.repository.NoteAboutOrder.createInstance(mongoose.connection);
|
|
13
13
|
|
|
14
14
|
let updateResult: any;
|
|
15
15
|
|
|
16
|
-
updateResult = await
|
|
16
|
+
updateResult = await noteRepo.unsetUnnecessaryFields({
|
|
17
17
|
filter: {
|
|
18
|
-
|
|
19
|
-
// 'location.maximumAttendeeCapacity': { $exists: true },
|
|
20
|
-
maximumPhysicalAttendeeCapacity: { $exists: true }
|
|
18
|
+
'about.identifier': { $exists: true }
|
|
21
19
|
},
|
|
22
|
-
$unset:
|
|
23
|
-
'
|
|
20
|
+
$unset: {
|
|
21
|
+
'about.identifier': 1
|
|
24
22
|
}
|
|
25
23
|
});
|
|
26
24
|
console.log(updateResult);
|
|
@@ -26,16 +26,9 @@ export declare class NoteAboutOrderRepo {
|
|
|
26
26
|
id: string;
|
|
27
27
|
attributes: Pick<INoteAboutOrder, 'text' | 'editor'>;
|
|
28
28
|
}): Promise<void>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
_id: import("mongoose").Types.ObjectId;
|
|
34
|
-
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, import("./mongoose/schemas/note").IDocType> & Pick<import("@chevre/factory/lib/creativeWork/noteDigitalDocument").INoteDigitalDocument, "identifier" | "project" | "typeOf" | "text" | "version" | "dateCreated" | "dateModified" | "creator" | "editor" | "hasDigitalDocumentPermission"> & {
|
|
35
|
-
about: factory.creativeWork.noteDigitalDocument.IAbout;
|
|
36
|
-
provider: factory.creativeWork.noteDigitalDocument.IProviderAsProject | factory.creativeWork.noteDigitalDocument.IProviderAsSeller;
|
|
37
|
-
} & {
|
|
38
|
-
_id: import("mongoose").Types.ObjectId;
|
|
39
|
-
}>>;
|
|
29
|
+
unsetUnnecessaryFields(params: {
|
|
30
|
+
filter: FilterQuery<factory.creativeWork.noteDigitalDocument.INoteAboutOrder>;
|
|
31
|
+
$unset: any;
|
|
32
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
40
33
|
}
|
|
41
34
|
export {};
|
|
@@ -175,10 +175,22 @@ class NoteAboutOrderRepo {
|
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
getCursor(conditions
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
// public getCursor(conditions: FilterQuery<factory.creativeWork.noteDigitalDocument.INoteAboutOrder>, projection: any) {
|
|
179
|
+
// return this.noteModel.find(
|
|
180
|
+
// {
|
|
181
|
+
// ...conditions,
|
|
182
|
+
// 'about.typeOf': { $eq: factory.order.OrderType.Order }
|
|
183
|
+
// },
|
|
184
|
+
// projection
|
|
185
|
+
// )
|
|
186
|
+
// .sort({ dateCreated: factory.sortType.Ascending })
|
|
187
|
+
// .cursor();
|
|
188
|
+
// }
|
|
189
|
+
unsetUnnecessaryFields(params) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
return this.noteModel.updateMany(Object.assign(Object.assign({}, params.filter), { 'about.typeOf': { $eq: factory.order.OrderType.Order } }), { $unset: params.$unset }, { timestamps: false })
|
|
192
|
+
.exec();
|
|
193
|
+
});
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
196
|
exports.NoteAboutOrderRepo = NoteAboutOrderRepo;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
interface IOfferCatalogAsFindResult {
|
|
4
|
+
/**
|
|
5
|
+
* カタログID
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* 対象オファー
|
|
10
|
+
*/
|
|
11
|
+
aggregateElement: {
|
|
12
|
+
itemOffered: {
|
|
13
|
+
/**
|
|
14
|
+
* プロダクトID
|
|
15
|
+
*/
|
|
16
|
+
id: string;
|
|
17
|
+
typeOf: factory.product.ProductType;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* プロダクトオファーカタログリポジトリ
|
|
23
|
+
*/
|
|
24
|
+
export declare class ProductHasOfferCatalogRepo {
|
|
25
|
+
private readonly productModel;
|
|
26
|
+
constructor(connection: Connection);
|
|
27
|
+
findOfferCatalogs(params: {
|
|
28
|
+
limit?: number;
|
|
29
|
+
page?: number;
|
|
30
|
+
project?: {
|
|
31
|
+
id?: {
|
|
32
|
+
$eq?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
product?: {
|
|
36
|
+
id?: {
|
|
37
|
+
$eq?: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}): Promise<IOfferCatalogAsFindResult[]>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProductHasOfferCatalogRepo = void 0;
|
|
13
|
+
const mongoose_1 = require("mongoose");
|
|
14
|
+
const factory = require("../factory");
|
|
15
|
+
const settings_1 = require("../settings");
|
|
16
|
+
const product_1 = require("./mongoose/schemas/product");
|
|
17
|
+
/**
|
|
18
|
+
* プロダクトオファーカタログリポジトリ
|
|
19
|
+
*/
|
|
20
|
+
class ProductHasOfferCatalogRepo {
|
|
21
|
+
constructor(connection) {
|
|
22
|
+
this.productModel = connection.model(product_1.modelName, (0, product_1.createSchema)());
|
|
23
|
+
}
|
|
24
|
+
findOfferCatalogs(params) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a, _b, _c, _d;
|
|
27
|
+
const matchStages = [];
|
|
28
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
29
|
+
if (typeof projectIdEq === 'string') {
|
|
30
|
+
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
31
|
+
}
|
|
32
|
+
const productIdEq = (_d = (_c = params.product) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
|
|
33
|
+
if (typeof productIdEq === 'string') {
|
|
34
|
+
matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(productIdEq) } } });
|
|
35
|
+
}
|
|
36
|
+
const aggregate = this.productModel.aggregate([
|
|
37
|
+
{
|
|
38
|
+
$unwind: {
|
|
39
|
+
path: '$hasOfferCatalog.itemListElement'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
...matchStages,
|
|
43
|
+
{ $sort: { productID: factory.sortType.Ascending } },
|
|
44
|
+
{
|
|
45
|
+
$project: {
|
|
46
|
+
_id: 0,
|
|
47
|
+
id: '$hasOfferCatalog.itemListElement.id',
|
|
48
|
+
aggregateElement: {
|
|
49
|
+
itemOffered: {
|
|
50
|
+
id: { $toString: '$_id' },
|
|
51
|
+
typeOf: '$typeOf'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
]);
|
|
57
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
58
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
59
|
+
aggregate.skip(params.limit * (page - 1))
|
|
60
|
+
.limit(params.limit);
|
|
61
|
+
}
|
|
62
|
+
return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
63
|
+
.exec();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ProductHasOfferCatalogRepo = ProductHasOfferCatalogRepo;
|
|
@@ -56,6 +56,7 @@ import type { SectionRepo } from './repo/place/section';
|
|
|
56
56
|
import type { PotentialActionRepo } from './repo/potentialAction';
|
|
57
57
|
import type { PriceSpecificationRepo } from './repo/priceSpecification';
|
|
58
58
|
import type { ProductRepo } from './repo/product';
|
|
59
|
+
import type { ProductHasOfferCatalogRepo } from './repo/productHasOfferCatalog';
|
|
59
60
|
import type { ProductModelRepo } from './repo/productModel';
|
|
60
61
|
import type { ProductOfferRepo } from './repo/productOffer';
|
|
61
62
|
import type { ProjectRepo } from './repo/project';
|
|
@@ -348,6 +349,10 @@ export type Product = ProductRepo;
|
|
|
348
349
|
export declare namespace Product {
|
|
349
350
|
function createInstance(...params: ConstructorParameters<typeof ProductRepo>): Promise<ProductRepo>;
|
|
350
351
|
}
|
|
352
|
+
export type ProductHasOfferCatalog = ProductHasOfferCatalogRepo;
|
|
353
|
+
export declare namespace ProductHasOfferCatalog {
|
|
354
|
+
function createInstance(...params: ConstructorParameters<typeof ProductHasOfferCatalogRepo>): Promise<ProductHasOfferCatalogRepo>;
|
|
355
|
+
}
|
|
351
356
|
export type ProductModel = ProductModelRepo;
|
|
352
357
|
export declare namespace ProductModel {
|
|
353
358
|
function createInstance(...params: ConstructorParameters<typeof ProductModelRepo>): Promise<ProductModelRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Permit = exports.Person = exports.paymentMethod = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AdvanceBookingRequirement = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
|
|
13
|
-
exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = void 0;
|
|
13
|
+
exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = void 0;
|
|
14
14
|
var AcceptedOffer;
|
|
15
15
|
(function (AcceptedOffer) {
|
|
16
16
|
let repo;
|
|
@@ -802,6 +802,19 @@ var Product;
|
|
|
802
802
|
}
|
|
803
803
|
Product.createInstance = createInstance;
|
|
804
804
|
})(Product || (exports.Product = Product = {}));
|
|
805
|
+
var ProductHasOfferCatalog;
|
|
806
|
+
(function (ProductHasOfferCatalog) {
|
|
807
|
+
let repo;
|
|
808
|
+
function createInstance(...params) {
|
|
809
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
810
|
+
if (repo === undefined) {
|
|
811
|
+
repo = (yield Promise.resolve().then(() => require('./repo/productHasOfferCatalog'))).ProductHasOfferCatalogRepo;
|
|
812
|
+
}
|
|
813
|
+
return new repo(...params);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
ProductHasOfferCatalog.createInstance = createInstance;
|
|
817
|
+
})(ProductHasOfferCatalog || (exports.ProductHasOfferCatalog = ProductHasOfferCatalog = {}));
|
|
805
818
|
var ProductModel;
|
|
806
819
|
(function (ProductModel) {
|
|
807
820
|
let repo;
|
package/package.json
CHANGED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
const DAYS = 365;
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
-
|
|
11
|
-
const now = new Date();
|
|
12
|
-
let updateResult: any;
|
|
13
|
-
|
|
14
|
-
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const startIndex = 8760;
|
|
17
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
18
|
-
const hours = (DAYS * 24) + startIndex;
|
|
19
|
-
// tslint:disable-next-line:no-increment-decrement no-magic-numbers
|
|
20
|
-
for (let index = startIndex; index < hours; index++) {
|
|
21
|
-
// for (let index = 0; index < hours; index++) {
|
|
22
|
-
updateResult = await actionRepo.unsetUnnecessaryFields({
|
|
23
|
-
filter: {
|
|
24
|
-
// _id: { $eq: '667379e7be9a532411c29424' },
|
|
25
|
-
typeOf: { $eq: chevre.factory.actionType.CheckAction },
|
|
26
|
-
'object.typeOf': { $exists: true, $eq: chevre.factory.service.paymentService.PaymentServiceType.MovieTicket },
|
|
27
|
-
actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
|
|
28
|
-
startDate: {
|
|
29
|
-
$gte: moment(now)
|
|
30
|
-
.add(-(index + 1), 'hours')
|
|
31
|
-
.toDate(),
|
|
32
|
-
$lt: moment(now)
|
|
33
|
-
.add(-index, 'hours')
|
|
34
|
-
.toDate()
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
$unset: {
|
|
38
|
-
'result.purchaseNumberAuthIn': 1,
|
|
39
|
-
'result.purchaseNumberAuthResult': 1
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
console.log('unset processed.', updateResult, -(index + 1), 'hours', -index, 'hours');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
console.log(DAYS, 'days processed');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
main()
|
|
49
|
-
.then()
|
|
50
|
-
.catch(console.error);
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
const DAYS = 500;
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
-
|
|
11
|
-
const now = new Date();
|
|
12
|
-
let updateResult: any;
|
|
13
|
-
|
|
14
|
-
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
17
|
-
const hours = DAYS * 24;
|
|
18
|
-
// tslint:disable-next-line:no-increment-decrement no-magic-numbers
|
|
19
|
-
for (let index = 0; index < hours; index++) {
|
|
20
|
-
updateResult = await transactionRepo.unsetUnnecessaryFields({
|
|
21
|
-
filter: {
|
|
22
|
-
// _id: { $eq: '649a7654ff1c885bcc40bbb7' },
|
|
23
|
-
typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
|
|
24
|
-
status: { $eq: chevre.factory.transactionStatusType.Confirmed },
|
|
25
|
-
startDate: {
|
|
26
|
-
$gte: moment(now)
|
|
27
|
-
.add(-(index + 1), 'hours')
|
|
28
|
-
.toDate(),
|
|
29
|
-
$lt: moment(now)
|
|
30
|
-
.add(-index, 'hours')
|
|
31
|
-
.toDate()
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
$unset: {
|
|
35
|
-
'result.order.acceptedOffers': 1
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
console.log('unset processed.', updateResult, -(index + 1), 'hours', -index, 'hours');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log(DAYS, 'days processed');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
main()
|
|
45
|
-
.then()
|
|
46
|
-
.catch(console.error);
|