Skip to content
Open
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
17 changes: 17 additions & 0 deletions todolist-day-2/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const TodoManager_1 = __importDefault(require("./models/TodoManager"));
const todo = new TodoManager_1.default();
todo.addTodo(1, 'Makan nasi', 'Makan nasi di rumah pak ahmad');
todo.addTodo(2, 'Tidur', 'Tidur sama teman');
todo.addTodo(3, 'Bermain', 'Bermain sama teman');
console.log('UNMODIFIED ID : 1 -> ', todo.getTodoById(1));
todo.getTodoById(1).setFinished = true;
todo.getTodoById(1).setTitle = 'Makan Bubur';
todo.getTodoById(1).setDesc = 'Makan bubur di rumah pak jamal';
todo.removeTodo(3);
console.log('MODIFIED ID : 1 -> ', todo.getTodoById(1));
console.log('ALL TODOS -> ', todo.getAllTodos());
21 changes: 21 additions & 0 deletions todolist-day-2/dist/models/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Todo {
constructor(id, title, desc) {
this.id = id;
this.title = title;
this.start = new Date();
this.desc = desc;
this.finished = false;
}
set setFinished(finished) {
this.finished = finished;
}
set setTitle(title) {
this.title = title;
}
set setDesc(desc) {
this.desc = desc;
}
}
exports.default = Todo;
8 changes: 8 additions & 0 deletions todolist-day-2/dist/models/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class TodoList {
constructor() {
this.todos = [];
}
}
exports.default = TodoList;
28 changes: 28 additions & 0 deletions todolist-day-2/dist/models/TodoManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const TodoList_1 = __importDefault(require("./TodoList"));
const Todo_1 = __importDefault(require("./Todo"));
class TodoManager extends TodoList_1.default {
constructor() {
super();
}
addTodo(id, title, desc) {
let newTodo = new Todo_1.default(id, title, desc);
this.todos.push(newTodo);
return newTodo;
}
removeTodo(id) {
this.todos = this.todos.filter((todo) => todo.id !== id);
}
getTodoById(id) {
let todo = this.todos.filter((todo) => todo.id === id)[0];
return todo;
}
getAllTodos() {
return this.todos;
}
}
exports.default = TodoManager;
2 changes: 2 additions & 0 deletions todolist-day-2/dist/types/todoTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
23 changes: 23 additions & 0 deletions todolist-day-2/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Todo from './models/TodoManager'

const todo = new Todo()

todo.addTodo(1, 'Makan nasi', 'Makan nasi di rumah pak ahmad')
todo.addTodo(2, 'Tidur', 'Tidur sama teman')
todo.addTodo(3, 'Bermain', 'Bermain sama teman')

console.log('----------------------------------------------')
console.log('UNMODIFIED ID : 1 -> ', todo.getTodoById(1))

todo.getTodoById(1).setFinished = true
todo.getTodoById(1).setTitle = 'Makan Bubur'
todo.getTodoById(1).setDesc = 'Makan bubur di rumah pak jamal'

todo.removeTodo(3)
console.log('----------------------------------------------')

console.log('MODIFIED ID : 1 -> ', todo.getTodoById(1))
console.log('----------------------------------------------')

console.log('ALL TODOS -> ', todo.getAllTodos())
console.log('----------------------------------------------')
27 changes: 27 additions & 0 deletions todolist-day-2/src/models/Todo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default class Todo {
id: number
title: string
start: Date
desc: string
finished: boolean

constructor(id: number, title: string, desc: string) {
this.id = id
this.title = title
this.start = new Date()
this.desc = desc
this.finished = false
}

set setFinished(finished: boolean) {
this.finished = finished
}

set setTitle(title: string) {
this.title = title
}

set setDesc(desc: string) {
this.desc = desc
}
}
9 changes: 9 additions & 0 deletions todolist-day-2/src/models/TodoList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ITodo } from '../types/todoTypes'

export default class TodoList {
todos: ITodo[]

constructor() {
this.todos = []
}
}
28 changes: 28 additions & 0 deletions todolist-day-2/src/models/TodoManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ITodoList, ITodo } from '../types/todoTypes'
import TodoList from './TodoList'
import Todo from './Todo'

export default class TodoManager extends TodoList implements ITodoList {
constructor() {
super()
}

addTodo(id: number, title: string, desc: string): ITodo {
let newTodo = new Todo(id, title, desc)
this.todos.push(newTodo)
return newTodo
}

removeTodo(id: number): void {
this.todos = this.todos.filter((todo) => todo.id !== id)
}

getTodoById(id: number): ITodo {
let todo = this.todos.filter((todo) => todo.id === id)[0]
return todo
}

getAllTodos() {
return this.todos
}
}
17 changes: 17 additions & 0 deletions todolist-day-2/src/types/todoTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface ITodo {
id: number
title: string
start: Date
desc: string
finished: boolean
setFinished: boolean
setTitle: string
setDesc: string
}

export interface ITodoList {
todos: ITodo[]
addTodo(id: number, title: string, desc: string): ITodo
removeTodo(id: number): void
getTodoById(id: number): ITodo
}
12 changes: 12 additions & 0 deletions todolist-day-2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"rootDir": "./src",
"outDir": "./dist"
}
}