Skip to content

Commit ba50ae3

Browse files
authored
Merge pull request #1 from afteracademy/interface-without-I
remove 'I' prefix from the interface - community request
2 parents d806881 + bbf4b20 commit ba50ae3

File tree

24 files changed

+180
-191
lines changed

24 files changed

+180
-191
lines changed

src/auth/authUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Tokens } from 'app-request';
22
import { AuthFailureError, InternalError } from '../core/ApiError';
33
import JWT, { JwtPayload } from '../core/JWT';
44
import { Types } from 'mongoose';
5-
import { IUser } from '../database/model/User';
5+
import User from '../database/model/User';
66
import { tokenInfo } from '../config';
77

88
export const validateTokenData = async (payload: JwtPayload, userId: Types.ObjectId): Promise<JwtPayload> => {
@@ -14,7 +14,7 @@ export const validateTokenData = async (payload: JwtPayload, userId: Types.Objec
1414
return payload;
1515
};
1616

17-
export const createTokens = async (user: IUser, accessTokenKey: string, refreshTokenKey: string)
17+
export const createTokens = async (user: User, accessTokenKey: string, refreshTokenKey: string)
1818
: Promise<Tokens> => {
1919
const accessToken = await JWT.encode(
2020
new JwtPayload(

src/database/model/ApiKey.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Schema, model, Document, Types } from 'mongoose';
33
export const DOCUMENT_NAME = 'ApiKey';
44
export const COLLECTION_NAME = 'api_keys';
55

6-
export interface IApiKey extends Document {
6+
export default interface ApiKey extends Document {
77
key: string;
88
version: number;
99
metadata: string;
@@ -49,6 +49,4 @@ const schema = new Schema(
4949
versionKey: false
5050
});
5151

52-
const ApiKey = model<IApiKey>(DOCUMENT_NAME, schema, COLLECTION_NAME);
53-
54-
export default ApiKey;
52+
export const ApiKeyModel = model<ApiKey>(DOCUMENT_NAME, schema, COLLECTION_NAME);

src/database/model/Blog.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { Schema, model, Document } from 'mongoose';
2-
import { IUser } from './User';
3-
import Logger from '../../core/Logger';
2+
import User from './User';
43

54
export const DOCUMENT_NAME = 'Blog';
65
export const COLLECTION_NAME = 'blogs';
76

8-
export interface IBlog extends Document {
7+
export default interface Blog extends Document {
98
title: string;
109
description: string;
1110
text?: string;
1211
draftText: string;
1312
tags: string[];
14-
author: IUser;
13+
author: User;
1514
imgUrl?: string;
1615
blogUrl: string;
1716
likes?: number;
@@ -21,8 +20,8 @@ export interface IBlog extends Document {
2120
isPublished: boolean;
2221
status?: boolean;
2322
publishedAt?: Date;
24-
createdBy?: IUser;
25-
updatedBy?: IUser;
23+
createdBy?: User;
24+
updatedBy?: User;
2625
createdAt?: Date;
2726
updatedAt?: Date;
2827
}
@@ -145,6 +144,4 @@ const schema = new Schema(
145144
{ weights: { title: 3, description: 1 }, background: false }
146145
);
147146

148-
const Blog = model<IBlog>(DOCUMENT_NAME, schema, COLLECTION_NAME);
149-
150-
export default Blog;
147+
export const BlogModel = model<Blog>(DOCUMENT_NAME, schema, COLLECTION_NAME);

src/database/model/Keystore.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Schema, model, Document } from 'mongoose';
2-
import { IUser } from './User';
2+
import User from './User';
33

44
export const DOCUMENT_NAME = 'Keystore';
55
export const COLLECTION_NAME = 'keystores';
66

7-
export interface IKeystore extends Document {
8-
client: IUser;
7+
export default interface Keystore extends Document {
8+
client: User;
99
primaryKey: string;
1010
secondaryKey: string;
1111
status?: boolean;
@@ -50,6 +50,4 @@ const schema = new Schema(
5050
versionKey: false
5151
});
5252

53-
const Keystore = model<IKeystore>(DOCUMENT_NAME, schema, COLLECTION_NAME);
54-
55-
export default Keystore;
53+
export const KeystoreModel = model<Keystore>(DOCUMENT_NAME, schema, COLLECTION_NAME);

src/database/model/Role.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const enum RoleCode {
1010
ADMIN = 'ADMIN',
1111
}
1212

13-
export interface IRole extends Document {
13+
export default interface Role extends Document {
1414
code: string;
1515
status?: boolean;
1616
createdAt?: Date;
@@ -48,6 +48,4 @@ const schema = new Schema(
4848
versionKey: false
4949
});
5050

51-
const Role = model<IRole>(DOCUMENT_NAME, schema, COLLECTION_NAME);
52-
53-
export default Role;
51+
export const RoleModel = model<Role>(DOCUMENT_NAME, schema, COLLECTION_NAME);

src/database/model/User.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { model, Schema, Document, Types } from 'mongoose';
2-
import { IRole } from './Role';
2+
import Role from './Role';
33

44
export const DOCUMENT_NAME = 'User';
55
export const COLLECTION_NAME = 'users';
66

7-
export interface IUser extends Document {
7+
export default interface User extends Document {
88
name: string;
99
email?: string;
1010
password?: string;
1111
profilePicUrl?: string;
12-
roles: IRole[];
12+
roles: Role[];
1313
verified?: boolean;
1414
status?: boolean;
1515
createdAt?: Date;
@@ -70,6 +70,4 @@ const schema = new Schema(
7070
versionKey: false
7171
});
7272

73-
const User = model<IUser>(DOCUMENT_NAME, schema, COLLECTION_NAME);
74-
75-
export default User;
73+
export const UserModel = model<User>(DOCUMENT_NAME, schema, COLLECTION_NAME);

src/database/repository/ApiKeyRepo.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ApiKey, { IApiKey } from '../model/ApiKey';
1+
import ApiKey, { ApiKeyModel } from '../model/ApiKey';
22

33
export default class ApiRepo {
44

5-
public static async findByKey(key: string): Promise<IApiKey> {
6-
return ApiKey.findOne({ key: key, status: true }).lean<IApiKey>().exec();
5+
public static async findByKey(key: string): Promise<ApiKey> {
6+
return ApiKeyModel.findOne({ key: key, status: true }).lean<ApiKey>().exec();
77
}
88
}

src/database/repository/BlogRepo.ts

+51-51
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,135 @@
1-
import Blog, { IBlog } from '../model/Blog';
1+
import Blog, { BlogModel } from '../model/Blog';
22
import { Types } from 'mongoose';
3-
import { IUser } from '../model/User';
3+
import User from '../model/User';
44

55
export default class BlogRepo {
66

77
private static AUTHOR_DETAIL = 'name profilePicUrl';
88
private static BLOG_INFO_ADDITIONAL = '+isSubmitted +isDraft +isPublished +createdBy +updatedBy';
99
private static BLOG_ALL_DATA = '+text +draftText +isSubmitted +isDraft +isPublished +status +createdBy +updatedBy';
1010

11-
public static async create(blog: IBlog): Promise<IBlog> {
11+
public static async create(blog: Blog): Promise<Blog> {
1212
const now = new Date();
1313
blog.createdAt = now;
1414
blog.updatedAt = now;
15-
const createdBlog = await Blog.create(blog);
15+
const createdBlog = await BlogModel.create(blog);
1616
return createdBlog.toObject();
1717
}
1818

19-
public static update(blog: IBlog): Promise<any> {
19+
public static update(blog: Blog): Promise<any> {
2020
blog.updatedAt = new Date();
21-
return Blog.updateOne({ _id: blog._id }, { $set: { ...blog } }).lean<IBlog>().exec();
21+
return BlogModel.updateOne({ _id: blog._id }, { $set: { ...blog } }).lean<Blog>().exec();
2222
}
2323

24-
public static findInfoById(id: Types.ObjectId): Promise<IBlog> {
25-
return Blog.findOne({ _id: id, status: true })
24+
public static findInfoById(id: Types.ObjectId): Promise<Blog> {
25+
return BlogModel.findOne({ _id: id, status: true })
2626
.populate('author', this.AUTHOR_DETAIL)
27-
.lean<IBlog>()
27+
.lean<Blog>()
2828
.exec();
2929
}
3030

31-
public static findInfoWithTextById(id: Types.ObjectId): Promise<IBlog> {
32-
return Blog.findOne({ _id: id, status: true })
31+
public static findInfoWithTextById(id: Types.ObjectId): Promise<Blog> {
32+
return BlogModel.findOne({ _id: id, status: true })
3333
.select('+text')
3434
.populate('author', this.AUTHOR_DETAIL)
35-
.lean<IBlog>()
35+
.lean<Blog>()
3636
.exec();
3737
}
3838

39-
public static findInfoWithTextAndDraftTextById(id: Types.ObjectId): Promise<IBlog> {
40-
return Blog.findOne({ _id: id, status: true })
39+
public static findInfoWithTextAndDraftTextById(id: Types.ObjectId): Promise<Blog> {
40+
return BlogModel.findOne({ _id: id, status: true })
4141
.select('+text +draftText +isSubmitted +isDraft +isPublished +status')
4242
.populate('author', this.AUTHOR_DETAIL)
43-
.lean<IBlog>()
43+
.lean<Blog>()
4444
.exec();
4545
}
4646

47-
public static findBlogAllDataById(id: Types.ObjectId): Promise<IBlog> {
48-
return Blog.findOne({ _id: id, status: true })
47+
public static findBlogAllDataById(id: Types.ObjectId): Promise<Blog> {
48+
return BlogModel.findOne({ _id: id, status: true })
4949
.select(this.BLOG_ALL_DATA)
5050
.populate('author', this.AUTHOR_DETAIL)
51-
.lean<IBlog>()
51+
.lean<Blog>()
5252
.exec();
5353
}
5454

55-
public static findByUrl(blogUrl: string): Promise<IBlog> {
56-
return Blog.findOne({ blogUrl: blogUrl, status: true })
55+
public static findByUrl(blogUrl: string): Promise<Blog> {
56+
return BlogModel.findOne({ blogUrl: blogUrl, status: true })
5757
.select('+text')
5858
.populate('author', this.AUTHOR_DETAIL)
59-
.lean<IBlog>()
59+
.lean<Blog>()
6060
.exec();
6161
}
6262

63-
public static findUrlIfExists(blogUrl: string): Promise<IBlog> {
64-
return Blog.findOne({ blogUrl: blogUrl }).lean<IBlog>().exec();
63+
public static findUrlIfExists(blogUrl: string): Promise<Blog> {
64+
return BlogModel.findOne({ blogUrl: blogUrl }).lean<Blog>().exec();
6565
}
6666

67-
public static findByTagAndPaginated(tag: string, pageNumber: number, limit: number): Promise<IBlog[]> {
68-
return Blog.find({ tags: tag, status: true, isPublished: true })
67+
public static findByTagAndPaginated(tag: string, pageNumber: number, limit: number): Promise<Blog[]> {
68+
return BlogModel.find({ tags: tag, status: true, isPublished: true })
6969
.skip(limit * (pageNumber - 1))
7070
.limit(limit)
7171
.populate('author', this.AUTHOR_DETAIL)
7272
.sort({ updatedAt: -1 })
73-
.lean<IBlog>()
73+
.lean<Blog>()
7474
.exec();
7575
}
7676

77-
public static findAllPublishedForAuthor(user: IUser): Promise<IBlog[]> {
78-
return Blog.find({ author: user, status: true, isPublished: true })
77+
public static findAllPublishedForAuthor(user: User): Promise<Blog[]> {
78+
return BlogModel.find({ author: user, status: true, isPublished: true })
7979
.populate('author', this.AUTHOR_DETAIL)
8080
.sort({ updatedAt: -1 })
81-
.lean<IBlog>()
81+
.lean<Blog>()
8282
.exec();
8383
}
8484

85-
public static findAllDrafts(): Promise<IBlog[]> {
85+
public static findAllDrafts(): Promise<Blog[]> {
8686
return this.findDetailedBlogs({ isDraft: true, status: true });
8787
}
8888

89-
public static findAllSubmissions(): Promise<IBlog[]> {
89+
public static findAllSubmissions(): Promise<Blog[]> {
9090
return this.findDetailedBlogs({ isSubmitted: true, status: true });
9191
}
9292

93-
public static findAllPublished(): Promise<IBlog[]> {
93+
public static findAllPublished(): Promise<Blog[]> {
9494
return this.findDetailedBlogs({ isPublished: true, status: true });
9595
}
9696

97-
public static findAllSubmissionsForWriter(user: IUser): Promise<IBlog[]> {
97+
public static findAllSubmissionsForWriter(user: User): Promise<Blog[]> {
9898
return this.findDetailedBlogs({ author: user, status: true, isSubmitted: true });
9999
}
100100

101-
public static findAllPublishedForWriter(user: IUser): Promise<IBlog[]> {
101+
public static findAllPublishedForWriter(user: User): Promise<Blog[]> {
102102
return this.findDetailedBlogs({ author: user, status: true, isPublished: true });
103103
}
104104

105-
public static findAllDraftsForWriter(user: IUser): Promise<IBlog[]> {
105+
public static findAllDraftsForWriter(user: User): Promise<Blog[]> {
106106
return this.findDetailedBlogs({ author: user, status: true, isDraft: true });
107107
}
108108

109-
private static findDetailedBlogs(query: Object): Promise<IBlog[]> {
110-
return Blog.find(query)
109+
private static findDetailedBlogs(query: Object): Promise<Blog[]> {
110+
return BlogModel.find(query)
111111
.select(this.BLOG_INFO_ADDITIONAL)
112112
.populate('author', this.AUTHOR_DETAIL)
113113
.populate('createdBy', this.AUTHOR_DETAIL)
114114
.populate('updatedBy', this.AUTHOR_DETAIL)
115115
.sort({ updatedAt: -1 })
116-
.lean<IBlog>()
116+
.lean<Blog>()
117117
.exec();
118118
}
119119

120-
public static findLatestBlogs(pageNumber: number, limit: number): Promise<IBlog[]> {
121-
return Blog.find({ status: true, isPublished: true })
120+
public static findLatestBlogs(pageNumber: number, limit: number): Promise<Blog[]> {
121+
return BlogModel.find({ status: true, isPublished: true })
122122
.skip(limit * (pageNumber - 1))
123123
.limit(limit)
124124
.populate('author', this.AUTHOR_DETAIL)
125125
.sort({ publishedAt: -1 })
126-
.lean<IBlog>()
126+
.lean<Blog>()
127127
.exec();
128128
}
129129

130-
public static searchSimilarBlogs(blog: IBlog, limit: number)
131-
: Promise<IBlog[]> {
132-
return Blog.find(
130+
public static searchSimilarBlogs(blog: Blog, limit: number)
131+
: Promise<Blog[]> {
132+
return BlogModel.find(
133133
{
134134
$text: { $search: blog.title, $caseSensitive: false },
135135
status: true,
@@ -143,12 +143,12 @@ export default class BlogRepo {
143143
.sort({ updatedAt: -1 })
144144
.limit(limit)
145145
.sort({ similarity: { $meta: 'textScore' } })
146-
.lean<IBlog>()
146+
.lean<Blog>()
147147
.exec();
148148
}
149149

150-
public static search(query: string, limit: number): Promise<IBlog[]> {
151-
return Blog.find(
150+
public static search(query: string, limit: number): Promise<Blog[]> {
151+
return BlogModel.find(
152152
{
153153
$text: { $search: query, $caseSensitive: false },
154154
status: true,
@@ -160,12 +160,12 @@ export default class BlogRepo {
160160
.select('-status -description')
161161
.limit(limit)
162162
.sort({ similarity: { $meta: 'textScore' } })
163-
.lean<IBlog>()
163+
.lean<Blog>()
164164
.exec();
165165
}
166166

167-
public static searchLike(query: string, limit: number): Promise<IBlog[]> {
168-
return Blog.find(
167+
public static searchLike(query: string, limit: number): Promise<Blog[]> {
168+
return BlogModel.find(
169169
{
170170
title: { $regex: `.*${query}.*`, $options: 'i' },
171171
status: true,
@@ -174,7 +174,7 @@ export default class BlogRepo {
174174
.select('-status -description')
175175
.limit(limit)
176176
.sort({ score: -1 })
177-
.lean<IBlog>()
177+
.lean<Blog>()
178178
.exec();
179179
}
180180
}

0 commit comments

Comments
 (0)