-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎨 Rota Campaign, CampaignDAO e Campaign object
- Loading branch information
Gustavo Ueti
committed
Oct 7, 2021
1 parent
ee584ed
commit c9b4195
Showing
8 changed files
with
591 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Campaign = void 0; | ||
class Campaign { | ||
constructor(name, company, agency, campaignId, activate = true, created) { | ||
this._name = name; | ||
this._company = company; | ||
this._agency = agency; | ||
this._campaignId = campaignId; | ||
this._activate = activate; | ||
this._created = created; | ||
} | ||
toJson() { | ||
return { | ||
company: this._company, | ||
agency: this._agency, | ||
campaignId: this._campaignId, | ||
created: this._created, | ||
activate: this._activate, | ||
}; | ||
} | ||
get name() { | ||
return this._name; | ||
} | ||
get agency() { | ||
return this._agency; | ||
} | ||
get company() { | ||
return this._company; | ||
} | ||
get created() { | ||
return this._created; | ||
} | ||
get activate() { | ||
return this._activate; | ||
} | ||
get campaignId() { | ||
return this._campaignId; | ||
} | ||
} | ||
exports.Campaign = Campaign; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CampaignDAO = void 0; | ||
const FirestoreConnectionSingleton_1 = require("../cloud/FirestoreConnectionSingleton"); | ||
class CampaignDAO { | ||
constructor(campaign, agency) { | ||
this._campaignName = campaign; | ||
this._agency = agency; | ||
this._objectStore = FirestoreConnectionSingleton_1.FirestoreConnectionSingleton.getInstance(); | ||
this._pathToCollection = ['campaigns']; | ||
this._authCollection = this._objectStore.getCollection(this._pathToCollection); | ||
} | ||
addCampaign(campaign) { | ||
return this._objectStore | ||
.addDocumentIn(this._authCollection, campaign.toJson(), campaign.name) | ||
.get() | ||
.then(() => { | ||
return true; | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
return false; | ||
}); | ||
} | ||
deactivateCampaign(campaignName, agency, userRequestPermission) { | ||
return this._objectStore | ||
.getCollection(this._pathToCollection) | ||
.doc(campaignName) | ||
.get() | ||
.then((doc) => { | ||
const campaign = doc.data(); | ||
if (campaign.agency === agency && | ||
(userRequestPermission === 'admin' || | ||
userRequestPermission === 'owner' || | ||
userRequestPermission === 'agencyOwner')) { | ||
campaign.activate = false; | ||
} | ||
else { | ||
throw new Error('Permissões insuficientes para inavitar a campanha!'); | ||
} | ||
return doc.ref.set(campaign); | ||
}) | ||
.then(() => { | ||
return true; | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
} | ||
reactivateCampaign(campaignName, agency, userRequestPermission) { | ||
return this._objectStore | ||
.getCollection(this._pathToCollection) | ||
.doc(campaignName) | ||
.get() | ||
.then((doc) => { | ||
const campaign = doc.data(); | ||
if (campaign.agency === agency && | ||
(userRequestPermission === 'admin' || | ||
userRequestPermission === 'owner' || | ||
userRequestPermission === 'agencyOwner')) { | ||
campaign.activate = true; | ||
} | ||
else { | ||
throw new Error('Permissões insuficientes para reativar a campanha!'); | ||
} | ||
return doc.ref.set(campaign); | ||
}) | ||
.then(() => { | ||
return true; | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
} | ||
} | ||
exports.CampaignDAO = CampaignDAO; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RoutesPermission = void 0; | ||
class RoutesPermission { | ||
constructor(route, method) { | ||
this._method = method; | ||
this._route = route; | ||
} | ||
validatePermission(user) { | ||
const agencyPostRoutes = ['/build/.*', '/csv', '/user/changepass', '/logout', '/login', '/campaign/add']; | ||
const agencyGetRoutes = ['/config', '/template', '/csv/list', '/csv', '/user', '/campaign/list', '/campaign/teste']; | ||
if (user.permission === 'user') { | ||
if (this._method === 'POST') { | ||
return agencyPostRoutes.filter((route) => new RegExp(route).test(this._route)).length > 0; | ||
} else if (this._method === 'GET') { | ||
return agencyGetRoutes.filter((route) => new RegExp(route).test(this._route)).length > 0; | ||
} else { | ||
return false; | ||
} | ||
} else if (user.permission === 'admin' || user.permission === 'owner') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
constructor(route, method) { | ||
this._method = method; | ||
this._route = route; | ||
} | ||
validatePermission(user) { | ||
const agencyPostRoutes = [ | ||
'/build/.*', | ||
'/csv', | ||
'/user/changepass', | ||
'/logout', | ||
'/login', | ||
'/campaign/add', | ||
'/campaign/deactivate', | ||
'/campaign/reactivate', | ||
]; | ||
const agencyGetRoutes = ['/config', '/template', '/csv/list', '/csv', '/user', '/campaign/list', '/campaign/teste']; | ||
if (user.permission === 'user') { | ||
if (this._method === 'POST') { | ||
return agencyPostRoutes.filter((route) => new RegExp(route).test(this._route)).length > 0; | ||
} | ||
else if (this._method === 'GET') { | ||
return agencyGetRoutes.filter((route) => new RegExp(route).test(this._route)).length > 0; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
else if (user.permission === 'admin' || user.permission === 'owner') { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
} | ||
exports.RoutesPermission = RoutesPermission; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { RoutesPermission } from './RoutesPermission'; | ||
|
||
export class Campaign { | ||
private _name: string; | ||
private _company: string; | ||
private _agency: string; | ||
private _campaignId: string; | ||
private _activate: boolean; | ||
private _created: string; | ||
|
||
constructor(name: string, company: string, agency: string, campaignId: string, activate = true, created: string) { | ||
this._name = name; | ||
this._company = company; | ||
this._agency = agency; | ||
this._campaignId = campaignId; | ||
this._activate = activate; | ||
this._created = created; | ||
} | ||
|
||
/** | ||
* Gera um JSON correspondente ao objeto Campaign | ||
* @returns JSON correspondente ao objeto Campaign | ||
*/ | ||
public toJson(): { [key: string]: string | boolean } { | ||
return { | ||
company: this._company, | ||
agency: this._agency, | ||
campaignId: this._campaignId, | ||
created: this._created, | ||
activate: this._activate, | ||
}; | ||
} | ||
|
||
get name(): string { | ||
return this._name; | ||
} | ||
|
||
get agency(): string { | ||
return this._agency; | ||
} | ||
|
||
get company(): string { | ||
return this._company; | ||
} | ||
|
||
get created(): string { | ||
return this._created; | ||
} | ||
|
||
get activate(): boolean { | ||
return this._activate; | ||
} | ||
|
||
get campaignId(): string { | ||
return this._campaignId; | ||
} | ||
} |
Oops, something went wrong.