Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing_seeds_example #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

21 changes: 21 additions & 0 deletions LivvieHandler.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EventManager } from "./livvie-event-bus/EventManager.mjs";

export class LivvieHandler {
/**@type {EventManager} */
#eventManager;
constructor() {
}
/**
*
* @param {EventManager} eventManager
*/
setEventManager(eventManager) {
this.#eventManager = eventManager;
}
get eventManager() {
if (!this.#eventManager) {
throw new Error('Event manager not set');
}
return this.#eventManager;
}
}
35 changes: 35 additions & 0 deletions authentication/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Module folder

## About
- A module is domain from solution. It can be related to a macro product or a threatre.
- It can be a common domain not binded to a macro product but the intersection between some or a utils domains.

## Folder format
- module/
- archetype1/
- commons/
- submodule/
- /implementations
- /implementation1
- {anyFolderformat}
- ImplementationConcreteClass
- ImplementationConcreteClass.spec
- /Interfaces
- /{SubmoduleRelatedErrors}
- /EventRequestInterface
- /EventResponseInterface
- /EventInterface
- /Token
- subModule2/
- archetype2/
- ...So on

## Types of folders
- Archetype:
- refers to a subgroup of the architecture.
- It is detailed on specific readme
- commons:
- It is helpers used in that scope
- subModule:
- It is a event. One which is called by other events
- The granular unit of the architecture
9 changes: 9 additions & 0 deletions authentication/data-acesses/commons/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Commons

## About:
- Each sub module can have a commons package which represents common functions used by more than one event in a sub-module

## Directory format
- It is compose by folders which represent an helper domain.
- There is no directory format to the helper domain, It is design related instead of architecture related.
- We can define a pattern if It is decided
11 changes: 11 additions & 0 deletions authentication/data-acesses/commons/mongoose/models/UserModel.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mongoose from "mongoose";

const UserSchema = new mongoose.Schema({
name: String,
email: String,
password: String,
role: String
});

const UserModel = mongoose.model("User", UserSchema);
export {UserModel}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UserModel } from "../../../commons/mongoose/models/UserModel.mjs";
import { IFindByEmailPasswordEvent } from "../../interfaces/IFindByEmailPassword.mjs";
import { IFindByEmailPasswordRequest } from "../../interfaces/IFindByEmailPasswordRequest.mjs";
import { IFindByEmailPasswordResponse } from "../../interfaces/IFindByEmailPasswordResponse.mjs";
import { UserNotFoundByEmailPassword } from "../../interfaces/UserNotFoundFindByEmailError.mjs";
/**
* @class
* @implements {IFindByEmailPasswordEvent}
*/
export class FindByEmailPasswordMongo {
/**
*
* @param {IFindByEmailPasswordRequest} arg
* @returns {Promise<IFindByEmailPasswordResponse>}
*/
async run({email, password}) {
const user = await UserModel.findOne({email, password});
if(!user) throw new UserNotFoundByEmailPassword(null, {email})
return {
id: user._id.toString(),
name: user.name
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Module relations: Low
// Module complexity: Low
// Conclusion: No Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createEvent } from "../../../../livvie-event-bus/createEvent.mjs";
import { IFindByEmailPasswordEvent } from "./IFindByEmailPassword.mjs";

const {TOKEN: FIND_BY_EMAIL_PASSWORD_TOKEN} = createEvent(IFindByEmailPasswordEvent);
export {FIND_BY_EMAIL_PASSWORD_TOKEN};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ILivvieEvent } from "../../../../livvie-event-bus/ILivvieEvent.mjs";
import { IFindByEmailPasswordRequest } from "./IFindByEmailPasswordRequest.mjs";
import { IFindByEmailPasswordResponse } from "./IFindByEmailPasswordResponse.mjs";
import { UserNotFoundByEmailPassword } from "./UserNotFoundFindByEmailError.mjs";

/** @interface */
/** @implements {ILivvieEvent} */
export class IFindByEmailPasswordEvent {
/**
*
* @param {IFindByEmailPasswordRequest} arg
* @returns {Promise<IFindByEmailPasswordResponse>}
* @throws {UserNotFoundByEmailPassword}
*/
async run(arg) {
throw new Error('run() must be implemented by subclass');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/**@interface */
export class IFindByEmailPasswordRequest {
/** @type {string} */
email;
/** @type {string} */
password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { EventError } from "../../../../livvie-event-bus/EventError.mjs";

/**@interface */
export class IFindByEmailPasswordResponse {
/** @type {string} */
name;
/** @type {string} */
id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EventError } from "../../../../livvie-event-bus/EventError.mjs";

export const ENTITY_NOT_FOUND = Symbol("NotFoundError");
export class UserNotFoundByEmailPassword extends EventError {
name = "FindByEmailError";
/** @type {Symbol} */
customType = ENTITY_NOT_FOUND
/** @type {string} */
email;
/**
*
* @param {Error | null} originalError
* @param {Object} param
* @param {string} param.email
*/
constructor(originalError, {email}) {
super(originalError, `User with email ${email} not found`);

this.email = email;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LivvieHandler } from '../../../../LivvieHandler.mjs';
import { FIND_AUTHOR_BY_ID_TOKEN } from '../../../../pretty-new-author/data-acesses/interfaces/FIND_AUTHOR_BY_ID_TOKEN.mjs';
import { FIND_BY_EMAIL_PASSWORD_TOKEN } from '../../../data-acesses/find-by-email-password/interfaces/FIND_BY_EMAIL_PASSWORD_TOKEN.mjs';
import { GENERATE_JWT_TOKEN } from '../../../use-cases/generate-JWT/Interfaces/GENERATE_JWT_TOKEN.mjs';
import { ILoginByEmailPasswordHandler } from '../interfaces/ILoginByEmailPasswordHandler.mjs';
import { ILoginByEmailPasswordRequest } from '../interfaces/ILoginByEmailPasswordRequest.mjs';
import { ILoginByEmailPasswordResponse } from '../interfaces/ILoginByEmailPasswordResponse.mjs';


/** @implements {ILoginByEmailPasswordHandler} */
export class LoginByEmailPasswordHandler extends LivvieHandler {
/**
*
* @param {ILoginByEmailPasswordRequest} arg
* @returns {Promise<ILoginByEmailPasswordResponse>}
* @throws
*/
async run({ email, password }) {
const {name, id} = await this.eventManager.retrieve(FIND_BY_EMAIL_PASSWORD_TOKEN).run({ email: email, password: password });
const { token } = await this.eventManager.retrieve(GENERATE_JWT_TOKEN).run({ name, id });
return { name, token };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Module Relation: High
// Module Complexity: Low
// Result: Integration Test
// Integration test: Routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ILivvieEvent } from "../../../../livvie-event-bus/ILivvieEvent.mjs";
import { ILoginByEmailPasswordRequest } from "./ILoginByEmailPasswordRequest.mjs";
import { ILoginByEmailPasswordResponse } from "./ILoginByEmailPasswordResponse.mjs";

/** @interface */
/** @implements {ILivvieEvent} */
export class ILoginByEmailPasswordHandler {
/**
*
* @param {ILoginByEmailPasswordRequest} request
* @returns {Promise<ILoginByEmailPasswordResponse>}
*/
async run(request) {
throw new Error('Not implemented');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @interface */
export class ILoginByEmailPasswordRequest {
/**@type {string} */
email;
/**@type {string} */
password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class
ILoginByEmailPasswordResponse {
/**@type {string} */
token;
/**@type {string} */
name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createEvent } from "../../../../livvie-event-bus/createEvent.mjs";
import { ILoginByEmailPasswordHandler} from "./ILoginByEmailPasswordHandler.mjs";

const {TOKEN: LOGIN_BY_EMAIL_PASSWORD_TOKEN} = createEvent(ILoginByEmailPasswordHandler);
export {LOGIN_BY_EMAIL_PASSWORD_TOKEN}
Loading