Skip to content

Instantly share code, notes, and snippets.

View moaaz-bhnas's full-sized avatar
🏠
Working remotely

Moaaz Bhnas moaaz-bhnas

🏠
Working remotely
View GitHub Profile
@rashidmya
rashidmya / @\@types\mongodb.ts
Last active December 3, 2024 07:49
nextjs-typescript-mongoose example
import { Mongoose } from 'mongoose';
/* eslint-disable no-var */
declare global {
var mongoose: {
promise: Promise<Mongoose> | null;
conn: Mongoose | null;
};
}
@aeciolevy
aeciolevy / Example.js
Created March 3, 2019 17:18
Example of mongoose transaction. MongoDB transaction example
exports.deleteUser = async (req, res, next) {
const session = await mongoose.startSession();
try {
const { id } = req.params;
// Start session
await session.startTransaction();
// deleteMany in this session
const [errorOp, result] = await toAll([App.deleteMany({ user: id }).session(session), UserModel.findByIdAndRemove(id).session(session)]);
if (errorOp) {
throw new ErrorRequest(STATUS_CODE.UNPROCESSABLE, errorOp.message);
@scokmen
scokmen / HttpStatusCode.ts
Created April 25, 2017 11:10
Typescript Http Status Codes Enum
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
@gaearon
gaearon / connect.js
Last active April 15, 2025 03:44
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (