|
|
@@ -524,7 +524,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private shouldUseV4ProcessForRevert(page): boolean {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const isV5Compatible = configManager.getConfig('app:isV5Compatible');
|
|
|
const isPageRestricted = page.grant === Page.GRANT_RESTRICTED;
|
|
|
@@ -535,7 +535,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private shouldNormalizeParent(page): boolean {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
return (
|
|
|
page.grant !== Page.GRANT_RESTRICTED &&
|
|
|
@@ -573,7 +573,7 @@ class PageService implements IPageService {
|
|
|
/*
|
|
|
* Common Operation
|
|
|
*/
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const parameters = {
|
|
|
ip: activityParameters.ip,
|
|
|
@@ -805,7 +805,7 @@ class PageService implements IPageService {
|
|
|
pageOpId: ObjectIdLike,
|
|
|
activity?,
|
|
|
): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const exParentId = page.parent;
|
|
|
|
|
|
@@ -938,7 +938,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private async getParentAndforceCreateEmptyTree(originalPage, toPath: string) {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const fromPath = originalPage.path;
|
|
|
const newParentPath = pathlib.dirname(toPath);
|
|
|
@@ -1075,7 +1075,7 @@ class PageService implements IPageService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const { updateMetadata, createRedirectPage } = options;
|
|
|
|
|
|
@@ -1351,7 +1351,7 @@ class PageService implements IPageService {
|
|
|
throw new Error('Cannot find or duplicate the empty page');
|
|
|
}
|
|
|
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
if (!isRecursively && page.isEmpty) {
|
|
|
throw Error('Page not found.');
|
|
|
@@ -1807,7 +1807,7 @@ class PageService implements IPageService {
|
|
|
oldPagePathPrefix,
|
|
|
newPagePathPrefix,
|
|
|
) {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const pageIds = pages.map((page) => page._id);
|
|
|
const revisions = await Revision.find({ pageId: { $in: pageIds } });
|
|
|
@@ -2127,7 +2127,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private async deleteNonEmptyTarget(page, user) {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const newPath = Page.getDeletedPageName(page.path);
|
|
|
|
|
|
const deletedPage = await Page.findByIdAndUpdate(
|
|
|
@@ -2248,7 +2248,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private async deleteDescendants(pages, user) {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const deletePageOperations: any[] = [];
|
|
|
const insertPageRedirectOperations: any[] = [];
|
|
|
@@ -2370,7 +2370,7 @@ class PageService implements IPageService {
|
|
|
|
|
|
async deleteCompletelyOperation(pageIds, pagePaths): Promise<void> {
|
|
|
// Delete Attachments, Revisions, Pages and emit delete
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const { attachmentService } = this.crowi;
|
|
|
const attachments = await Attachment.find({ page: { $in: pageIds } });
|
|
|
@@ -2935,7 +2935,7 @@ class PageService implements IPageService {
|
|
|
pageOpId: ObjectIdLike,
|
|
|
activity?,
|
|
|
): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const descendantsSubscribedSets = new Set();
|
|
|
await this.revertDeletedDescendantsWithStream(
|
|
|
@@ -2992,7 +2992,7 @@ class PageService implements IPageService {
|
|
|
newPath: string,
|
|
|
pageOpId: ObjectIdLike,
|
|
|
): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const newTarget = await Page.findOne({ path: newPath }); // only one page will be found since duplicating to existing path is forbidden
|
|
|
|
|
|
@@ -3112,7 +3112,7 @@ class PageService implements IPageService {
|
|
|
userRelatedGroups: PopulatedGrantedGroup[],
|
|
|
userRelatedParentGrantedGroups: IGrantedGroup[],
|
|
|
): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const operations: any = [];
|
|
|
|
|
|
pages.forEach((childPage) => {
|
|
|
@@ -3318,7 +3318,7 @@ class PageService implements IPageService {
|
|
|
pageIds: ObjectIdLike[] = [],
|
|
|
user?,
|
|
|
): Promise<Record<string, string | null>> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const MAX_LENGTH = 350;
|
|
|
|
|
|
// aggregation options
|
|
|
@@ -3513,7 +3513,7 @@ class PageService implements IPageService {
|
|
|
pageIds: ObjectIdLike[],
|
|
|
user,
|
|
|
): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const pages = await Page.findByIdsAndViewer(pageIds, user, null);
|
|
|
|
|
|
@@ -3533,7 +3533,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
async normalizeParentByPageIds(pageIds: ObjectIdLike[], user): Promise<void> {
|
|
|
- const Page = (await mongoose.model('Page')) as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const socket = this.crowi.socketIoService.getDefaultSocket();
|
|
|
|
|
|
@@ -3574,7 +3574,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private async normalizeParentByPage(page, user) {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const {
|
|
|
path,
|
|
|
@@ -3711,7 +3711,7 @@ class PageService implements IPageService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
const builder = new PageQueryBuilder(Page.findOne());
|
|
|
builder.addConditionAsOnTree();
|
|
|
@@ -3773,7 +3773,7 @@ class PageService implements IPageService {
|
|
|
pageOpId: ObjectIdLike,
|
|
|
): Promise<number> {
|
|
|
// Save prevDescendantCount for sub-operation
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
const builder = new PageQueryBuilder(Page.findOne(), true);
|
|
|
builder.addConditionAsOnTree();
|
|
|
@@ -3816,7 +3816,7 @@ class PageService implements IPageService {
|
|
|
pageOpId: ObjectIdLike,
|
|
|
options: { prevDescendantCount: number },
|
|
|
): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
try {
|
|
|
// update descendantCount of self and descendant pages first
|
|
|
@@ -3855,7 +3855,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
async _isPagePathIndexUnique() {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const now = new Date().toString();
|
|
|
const path = `growi_check_is_path_index_unique_${now}`;
|
|
|
|
|
|
@@ -3953,7 +3953,7 @@ class PageService implements IPageService {
|
|
|
isDuplicateOperation = false,
|
|
|
shouldEmitProgress = false,
|
|
|
): Promise<number> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const ancestorPaths = paths.flatMap((p) => collectAncestorPaths(p, []));
|
|
|
// targets' descendants
|
|
|
@@ -3992,7 +3992,7 @@ class PageService implements IPageService {
|
|
|
publicPathsToNormalize: string[],
|
|
|
grantFiltersByUser?: { $or: any[] } | null,
|
|
|
) {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const andFilter: any = {
|
|
|
$and: [
|
|
|
@@ -4051,7 +4051,7 @@ class PageService implements IPageService {
|
|
|
? this.crowi.socketIoService.getAdminSocket()
|
|
|
: null;
|
|
|
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
// Build filter
|
|
|
@@ -4295,7 +4295,7 @@ class PageService implements IPageService {
|
|
|
throw Error('user is required');
|
|
|
}
|
|
|
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
const builder = new PageQueryBuilder(Page.count(), false);
|
|
|
@@ -4418,7 +4418,7 @@ class PageService implements IPageService {
|
|
|
): any[] {
|
|
|
const aggregationPipeline: any[] = [];
|
|
|
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
// -- Filter by paths
|
|
|
aggregationPipeline.push({ $match: { path: { $in: paths } } });
|
|
|
@@ -4448,7 +4448,7 @@ class PageService implements IPageService {
|
|
|
onlyMigratedAsExistingPages = true,
|
|
|
andFilter?,
|
|
|
): Promise<any[]> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const pipeline = this.buildBasePipelineToCreateEmptyPages(
|
|
|
paths,
|
|
|
@@ -4475,7 +4475,7 @@ class PageService implements IPageService {
|
|
|
}
|
|
|
|
|
|
private async connectPageTree(path: string): Promise<void> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
const ancestorPaths = collectAncestorPaths(path);
|
|
|
@@ -4622,7 +4622,7 @@ class PageService implements IPageService {
|
|
|
path: string,
|
|
|
user?,
|
|
|
): void {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
pageDocument.path = path;
|
|
|
pageDocument.creator = user;
|
|
|
@@ -4671,7 +4671,7 @@ class PageService implements IPageService {
|
|
|
user?,
|
|
|
options?: IOptionsForCreate,
|
|
|
): Promise<boolean> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
// Operatability validation
|
|
|
const canOperate = await this.crowi.pageOperationService.canOperate(
|
|
|
@@ -5011,7 +5011,7 @@ class PageService implements IPageService {
|
|
|
body: string,
|
|
|
options: IOptionsForCreate & { grantUserIds?: ObjectIdLike[] },
|
|
|
): Promise<PageDocument> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
const isV5Compatible = configManager.getConfig('app:isV5Compatible');
|
|
|
if (!isV5Compatible) {
|
|
|
@@ -5496,7 +5496,7 @@ class PageService implements IPageService {
|
|
|
user: IUserHasId,
|
|
|
userGroups = null,
|
|
|
): Promise<HydratedDocument<IPage>[]> {
|
|
|
- const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
|
// https://regex101.com/r/KYZWls/1
|
|
|
// ex. /trash/.*
|