mongoose#Types TypeScript Examples
The following examples show how to use
mongoose#Types.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 8 votes |
@ApiOkResponse({
schema: {
type: 'object',
properties: {
data: {
$ref: getSchemaPath(User),
},
},
},
description: '200. Success. Returns a user',
})
@ApiNotFoundResponse({
description: '404. NotFoundException. User was not found',
})
@ApiUnauthorizedResponse({
schema: {
type: 'object',
example: {
message: 'string',
},
},
description: '401. UnauthorizedException.',
})
@ApiParam({ name: 'id', type: String })
@Get(':id')
@Serialize(UserResponseDto)
@Auth()
async getById(
@Param('id', ParseObjectIdPipe) id: Types.ObjectId,
): Promise<User> {
const foundUser = await this.usersService.getVerifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return foundUser;
}
Example #2
Source File: subscriptionDB.ts From one-platform with MIT License | 6 votes |
async getSubscriptionStatus(namespaceID: Types.ObjectId, schemaID: Types.ObjectId) {
const subscriber = this.context.user.id;
const dbDocs = await this.findByFields({ namespace: namespaceID, subscriber });
const subscription = dbDocs?.[0];
if (subscription) {
const subscribed = subscription.subscriptions.find(({ spec: id }) => id === schemaID);
return subscribed?.environments;
}
return null;
}
Example #3
Source File: auth.service.ts From nest-js-boilerplate with MIT License | 6 votes |
public createVerifyToken(id: Types.ObjectId): string {
return this.jwtService.sign(
{ id },
{
expiresIn: authConstants.jwt.expirationTime.accessToken,
secret: this.configService.get<string>('ACCESS_TOKEN') || '<%= config.accessTokenSecret %>',
},
);
}
Example #4
Source File: user.ts From your_spotify with GNU General Public License v3.0 | 6 votes |
storeFirstListenedAtIfLess = async (userId: string, playedAt: Date) => {
const id = new Types.ObjectId(userId);
const user = await getUserFromField('_id', id);
if (user && (!user.firstListenedAt || playedAt.getTime() < user.firstListenedAt.getTime())) {
await storeInUser('_id', id, {
firstListenedAt: playedAt,
});
}
}
Example #5
Source File: authUtils.ts From nodejs-backend-architecture-typescript with Apache License 2.0 | 6 votes |
validateTokenData = (payload: JwtPayload): boolean => {
if (
!payload ||
!payload.iss ||
!payload.sub ||
!payload.aud ||
!payload.prm ||
payload.iss !== tokenInfo.issuer ||
payload.aud !== tokenInfo.audience ||
!Types.ObjectId.isValid(payload.sub)
)
throw new AuthFailureError('Invalid Access Token');
return true;
}
Example #6
Source File: follow.ts From foodie with MIT License | 6 votes |
router.post(
'/v1/unfollow/:follow_id',
isAuthenticated,
validateObjectID('follow_id'),
async (req: Request, res: Response, next: NextFunction) => {
try {
const { follow_id } = req.params;
const user = User.findById(follow_id);
if (!user) return next(new ErrorHandler(400, 'The person you\'re trying to unfollow doesn\'t exist.'));
if (follow_id === req.user._id.toString()) return next(new ErrorHandler(400));
await Follow.deleteOne({
target: Types.ObjectId(follow_id),
user: req.user._id
});
// UNSUBSCRIBE TO PERSON'S FEED
await NewsFeed
.deleteMany({
post_owner: Types.ObjectId(follow_id),
follower: req.user._id
})
res.status(200).send(makeResponseJson({ state: false }));
} catch (e) {
console.log('CANT FOLLOW USER, ', e);
next(e);
}
}
);
Example #7
Source File: search.service.ts From Phantom with MIT License | 6 votes |
/**
* @author Dina Alaa <[email protected]>
* @descriptionget get my pins
* @param {String} name -name
* @param {Number} limit -limit
* @param {Number} offset -offset
* @returns {Object} -result: pin objects, length
*/
async getMyPins(name, userId, limit, offset): Promise<Object> {
if (!(await this.ValidationService.checkMongooseID([userId])))
throw new Error('not mongoose id');
let pin = await this.pinModel
.find({ 'creator.id': Types.ObjectId(userId) }, 'title note imageId')
.lean();
return await this.Fuzzy(pin, ['title', 'note'], name, limit, offset);
}
Example #8
Source File: built-in.ts From pebula-node with MIT License | 6 votes |
@GtSchemaType({
schemaType: Schema.Types.Array,
isContainer: true,
toSchema(reflectedType: typeof SchemaType | Schema, userType?: typeof SchemaType | Schema) {
const arraySchemaTypeOpts: SchemaTypeOpts<any> = {
type: [userType],
};
return arraySchemaTypeOpts;
},
})
export class DocumentArray<T extends MongooseDocument> extends Types.DocumentArray<T> {
}
Example #9
Source File: statics.ts From server with GNU General Public License v3.0 | 6 votes |
/**
* Checks the Credentials Collection for the Given ID
*
* @param {ICredentialsModel} this - Credentials Model
* @param {Types.ObjectId} id - Credential ID String
* @returns {Promise<boolean>} - Response whether true or false
*/
export function checkID(
this: ICredentialsModel,
id: Types.ObjectId,
): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
this.findById(id)
.then((creds: ICredentialsDoc | null) => {
if (creds) {
resolve(true);
} else {
resolve(false);
}
})
.catch((err: MongoError) => {
reject(new Error(`${err.name}: ${err.message}`));
});
});
}
Example #10
Source File: specstoreDB.ts From one-platform with MIT License | 5 votes |
async deleteSpecsOfANamespace(namespaceId: string) {
return this.model.deleteMany({ namespaceId: new Types.ObjectId(namespaceId) });
}
Example #11
Source File: users.repository.ts From nest-js-boilerplate with MIT License | 5 votes |
public async getById(id: Types.ObjectId): Promise<User | null> {
return this.usersModel.findOne({
_id: id,
}, { password: 0 }).lean();
}
Example #12
Source File: info.ts From your_spotify with GNU General Public License v3.0 | 5 votes |
InfosSchema = new Schema<Infos>(
{
owner: { type: Schema.Types.ObjectId, ref: 'User' },
id: { type: String, index: true },
played_at: Date,
},
{ toJSON: { virtuals: true }, toObject: { virtuals: true } },
)
Example #13
Source File: BlogRepo.ts From nodejs-backend-architecture-typescript with Apache License 2.0 | 5 votes |
public static findInfoById(id: Types.ObjectId): Promise<Blog | null> {
return BlogModel.findOne({ _id: id, status: true })
.populate('author', this.AUTHOR_DETAIL)
.lean<Blog>()
.exec();
}